Problems linking to dJointLibrary.lib

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Problems linking to dJointLibrary.lib

Postby misho » Sun Apr 24, 2016 4:56 pm

Hi all,

I'm trying to link my DLL to static (MT) dJointLibrary.lib, and I'm getting "error LNK2001: unresolved external symbol" on any dJointLibrary.lib method I try to use:

Code: Select all
1>NewtonMain.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static void __cdecl CustomAlloc::operator delete(void *)" (__imp_??3CustomAlloc@@SAXPAX@Z)
1>NewtonMain.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static void * __cdecl CustomAlloc::operator new(unsigned int)" (__imp_??2CustomAlloc@@SAPAXI@Z)


Linker finds the library and I get no compile errors. I build the release_double dJointLibrary.lib version myself. I use other Newton libs in the same way and everything is working. What am I missing?

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 552
Joined: Tue May 04, 2010 10:13 am

Re: Problems linking to dJointLibrary.lib

Postby Julio Jerez » Sun Apr 24, 2016 5:07 pm

no the project set up do no have configuration to link a static library with a dynamic dll.

I when over lot of aggravation in the pass try to get that going and it result in a combinatorial explosion of project config. so I decide to make simple. you use all DLL or all Statics, not mixing.
Julio Jerez
Moderator
Moderator
 
Posts: 11040
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problems linking to dJointLibrary.lib

Postby Sweenie » Sun Apr 24, 2016 5:38 pm

Hm, i don't think he is mixing static and dynamic newton libs, its his lib that is dynamic.
Try including the dcontainer.lib as well.
Sweenie
 
Posts: 490
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: Problems linking to dJointLibrary.lib

Postby Julio Jerez » Sun Apr 24, 2016 5:49 pm

Oh I see, but some how he is using dll link because I see the keywords __declspec(dllimport) and __imp_.

you are probably missing the define that tell the compile to ganerat static link library.
Maybe I forget that in the double configuration.
Julio Jerez
Moderator
Moderator
 
Posts: 11040
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problems linking to dJointLibrary.lib

Postby misho » Sun Apr 24, 2016 7:06 pm

Hi!

That's correct, I have "MyProject.dll", and to it I am linking newton static /MT libs.

Preprocessor defines for the dJointLibrary.lib are: (I don't think anything is missing...)

WIN32
NDEBUG
_WINDOWS
_USRDLL
_NEWTON_STATIC_LIB
_CUSTOM_JOINTS_STATIC_LIB
_CRT_SECURE_NO_WARNINGS
_NEWTON_USE_DOUBLE

I link and use core.lib, dMath.lib, newton.lib and physics.lib without any problems... but for some reason, dJointLibrary.lib (which builds without problem) gives me linker errors on any calls I make in dJointLib. I checked, dJointLibrary is being built as Static Library (.lib) with /MT runtimes, just as the others...

Even just creating a hinge:

Code: Select all
   CustomHinge* hinge;
   hinge = new CustomHinge (mChildMatrix, entChild->nBody, entParent->nBody);


I get 3 linker errors:

Code: Select all
1>NewtonMain.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static void __cdecl CustomAlloc::operator delete(void *)" (__imp_??3CustomAlloc@@SAXPAX@Z)
1>NewtonMain.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static void * __cdecl CustomAlloc::operator new(unsigned int)" (__imp_??2CustomAlloc@@SAPAXI@Z)
1>NewtonMain.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall CustomHinge::CustomHinge(class dMatrix const &,class NewtonBody * const,class NewtonBody * const)" (__imp_??0CustomHinge@@QAE@ABVdMatrix@@QAVNewtonBody@@1@Z)
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 552
Joined: Tue May 04, 2010 10:13 am

Re: Problems linking to dJointLibrary.lib

Postby Julio Jerez » Sun Apr 24, 2016 7:27 pm

did you add _CUSTOM_JOINTS_STATIC_LIB to your library? if you do not then the call will recule to dllimport.

if you open file customalloc .h

you will see that the import export is define if only if _CUSTOM_JOINTS_STATIC_LIB is not defined.

Code: Select all
#ifdef _CUSTOM_JOINTS_STATIC_LIB
   #define CUSTOM_JOINTS_API
#else
   #ifdef _CUSTOM_JOINTS_BUILD_DLL
      #ifdef _WIN32
         #define CUSTOM_JOINTS_API __declspec (dllexport)
      #else
         #define CUSTOM_JOINTS_API __attribute__ ((visibility("default")))
      #endif
   #else
      #ifdef _WIN32
         #define CUSTOM_JOINTS_API __declspec (dllimport)
      #else
         #define CUSTOM_JOINTS_API
      #endif
   #endif
#endif


so while the library is define it in the command line, when you include in your project if your project did no define in the command line or in a header file before the include was invoked then
CUSTOM_JOINTS_API will resolve to __declspec (dllimport)
Julio Jerez
Moderator
Moderator
 
Posts: 11040
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problems linking to dJointLibrary.lib

Postby misho » Sun Apr 24, 2016 8:22 pm

A-ha! I didn't realize I needed to define _CUSTOM_JOINTS_STATIC_LIB in my project as well! That solved it. Then it asked for dContainers.lib which I added and now it is working well.

Thank you sir!
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 552
Joined: Tue May 04, 2010 10:13 am

Re: Problems linking to dJointLibrary.lib

Postby Julio Jerez » Sun Apr 24, 2016 8:34 pm

dContainers.lib maybe be working because maybe a precompile header already has define. all if take is for you to move one header file around and I will break down.
you need to explicitly defined those macros so that there are not possible confusions.
Julio Jerez
Moderator
Moderator
 
Posts: 11040
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problems linking to dJointLibrary.lib

Postby misho » Tue Apr 26, 2016 3:05 pm

All good! Thanks!

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 552
Joined: Tue May 04, 2010 10:13 am


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 1 guest

cron