views:

49

answers:

1

So, I recently added a header file (and corresponding source file) to a project, along with a header file that file required, and an object file that the file required.

Everything compiles fine, unless I actually make a call to one of the functions declared in the newly added header file.

This is all using Visual Studio Express 2008.

To be more clear: Added:

E4407B.h (My code)

E4407B.cpp (Also my code, compiling as c)

ni4882.h (not mine - from National Instruments) ni4882.obj

When I call a function located in E4407B.h, I get the following error:

4>E4407B.obj : error LNK2005: _SA_GPIB_INTF already defined in test.obj
4>ni4882.obj : warning LNK4217: locally defined symbol _fclose imported in function _LoadFunction@4
4>ni4882.obj : warning LNK4217: locally defined symbol _fread imported in function _LoadFunction@4
4>ni4882.obj : warning LNK4217: locally defined symbol _fopen imported in function _LoadFunction@4
4>ni4882.obj : error LNK2019: unresolved external symbol __imp__rand referenced in function _LoadFunction@4
4>ni4882.obj : error LNK2019: unresolved external symbol __imp__srand referenced in function _LoadFunction@4
4>ni4882.obj : error LNK2019: unresolved external symbol __imp__time referenced in function _LoadFunction@4

test.c is where main is located.

Edit: I had in an error that shows up for building another solution which was in the build for some reason.

+1  A: 

It sounds like your header is defining objects (_SA_GPIB_INTF, _fclose, etc.) when it should only be declaring them. Any objects that require storage must only be defined in a single source file.

Also, the unresolved external symbol errors mean you're missing a library in the linking process (looks like the c standard library).

Without seeing the header code itself, it's hard to get any more specific.

Cogwheel - Matthew Orlando
I'm not sure what got it working, but I played around with some libraries (and changed a const in to a #define) and it now runs. Thanks.
Colin DeClue
Changing a const to a #define should not/cannot fix the linkage errors. If you have got everything working now, change the const back to the #define, and you will find that your code will still build.
IntelliChick