views:

454

answers:

3

Hi All,

I am compiling my project in the release mode in VC++. I have a .def file where i have declared the setLog and now i am getting following error

Linking... Creating library Release/HKL.lib and object Release/HKL.exp HKL_libinterface.obj : error LNK2001: unresolved external symbol _SCTP_setLog@8

Please help me on the above to fix the problem.

Thanks

A: 

If this compiles in Debug mode the most possible reason is that somehow the code where this function is implemented is not included into build - for example, the cpp file where it is implemented has "Excluded from build" set.

sharptooth
Yes it compiles fine in the debug mode..How to include a cpp file into the build set..plz tell me how..Thanks
You add it to the project tree in Solution Explorer. I guess you already have it added. Then you right-click, select "Properties" and check what's on the General tab. "Excluded form build" should be "No".
sharptooth
I see a checkbox for "Excluded form build" in the General tab where for all the cpp files this "Excluded form build" is unchecked (I guess it is NO).But then also i m facing the same error.
Okay. What is the setLog function definition? Is it in a .cpp or .h file?
sharptooth
it is a API exposed to the VB application.It is declared in the log.h file and defined in log.cpp
What is the complete declaration? I mean the "int setLog()" line. Also what is the corresponding line in the def file?
sharptooth
This is the declaration in the .h file:extern "C" int __stdcall setLog(log_type logType, bool isLog);This is defined in the .cpp file.The corresponding line in the def file is setLog @10
What if you replace @10 with PRIVATE?
sharptooth
No it does not help..i m still facing the same error.And i can not replace @10 with PRIVATE since this API is exposed to the VB application.Please suggest me what to do..
I did similar in my code and it works. Let's dig further. What is the function declaration in cpp? I mean the definition without the actual implementation.
sharptooth
In .cpp file it is declared as below:extern "C" int __stdcall setLog(log_type logType, bool isLog){ return LOGAPPCALLBACK()->openFile(logType, isLog);}
Looks allright. I'm no out of ideas.
sharptooth
A: 

As sharptooth mentioned, you most likely are not compiling the above function in your release build. In addition to looking for 'Excluded from build', check if you have any defines set (or not set) that would exclude the missing function from your release build.

Aaron Saarela
Hi can you please explain me in detail where and how to check this..:( i m new to this
+1  A: 

It sounds to me like you have a lib file configured in your debug build that is not in the release build. Your setLog() function does not seem to be the function the linker is complaining about - it sounds like it's not finding a function called SCTP_setLog().

Look in the list of libraries you have configured in your project's debug configuration and make sure they are also configured in the release configuration.

Michael Burr
This is the most likely case. Visual Studio makes you set every build option twice--once in Debug and once in Release--just in case you want them to be different (which sometimes, you do).
jeffamaphone
You *can* set both at once, but you have to remember that *before* you actually set the option :)
Thomas