Advertisement

Linking error.

Started by September 18, 2000 10:20 AM
3 comments, last by Mr Cucumber 24 years, 3 months ago
Now this is strange. At least I think so. I try to compile my MSVC project and I keep getting linker errors. I have a global function called Add. It is defined in a header and declared in a .cpp file (if I got the defined/declared stuff right). I get linker errors saying it is an unresolved external symbol. The weird part is that the file where they are declared is in the project because I can find the function in the wizard bar on globals. What could be wrong?
Declare your function in a header file like so:

extern int a();

then in a source file that includes that header do this:

int a() {
return 69;
};

then include the header file in your main source file, and you will see a(). That should do the trick!

Edited by - NBGH on September 18, 2000 12:27:28 PM
Advertisement
Make sure the cpp file that contains the implementation for add is inside of your project. Also make sure the definition matches the decleration.

//In your header file, you should have the decleration:int Add(int num1, int num2);//Then in your cpp file you should have the definition.int Add(int num1, int num2)    {    return num1+num2;    } 



Later,
Eck

Edited by - Eck on September 18, 2000 12:12:36 PM

EckTech Games - Games and Unity Assets I'm working on
Still Flying - My GameDev journal
The Shilwulf Dynasty - Campaign notes for my Rogue Trader RPG

Actually, declaring functions as ''extern'' is only a C thing, you don''t need to do it in C++, so that shouldn''t be the problem.

The problem is probably a typo somewhere, but we can''t tell unless you copy and paste some source.
What you are describing:
    // File: add.hvoid add(...);(Seperate file)// File add.cpp#include "add.h"void add(...){  // code....}    


Make sure you use quotes around that add.h in add.cpp, not < and >. If all else fails, post some code!

=======================================
A man with no head is still a man.
A head with no man is plain freaky.

This topic is closed to new replies.

Advertisement