problems linking under msvc 2013

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

problems linking under msvc 2013

Postby LordHexahedron » Thu Sep 22, 2016 12:35 am

Alright, so as may have been evident from my previous post - my mingw32 environment is broken beyond repair, it can't even compile trivial code in C++11 mode which is required for newton.

so thus the logical choice is MSVC, surely microsoft can make a compiler that works for their own platform in some rudimentary fashion... well, seemingly at least.

so first things first, I go to coreLibrary_300\projects\windows\project_vs2013
and in this folder I find four vcxproj files, no solutions but w/e - don't need 'em.

anyway - I spot that there are what appears to be four separate vcxproj files.
ampPhysics.vcxproj
core.vcxproj
newton.vcxproj
physics.vcxproj


alright - let's build 'em, all are set to win32 release (not releaseDLL - static makes for a simpler distribution package, will use dynamic if that's the only supported but the default was debug and not debugDLL which implies a functional static library configuration).

this gives me core.lib, ampPhysics.lib, newton.lib, and physics.lib.

next I add these to my libraries folder, and specify them to be linked (tried both the additional dependencies and #pragma comment(lib, "") approach - it finds the libraries just fine either way, it just can't find the symbols within)

This is simple enough, time to build.
Code: Select all
2>------ Build started: Project: protolib, Configuration: Release Win32 ------
2>  protolib.cpp
2>protolib.cpp(121): warning C4244: 'argument' : conversion from 'double' to 'dFloat', possible loss of data
2> 
2>  Searching libraries
2>      Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\msvcprt.lib:
2>      Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\MSVCRT.lib:
2>      Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\OLDNAMES.lib:
2>      Searching C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x86\kernel32.lib:
2>      Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\msvcprt.lib:
2>      Searching C:\lib\newton.lib:
2>      Searching C:\lib\core.lib:
2>      Searching C:\lib\Mondlicht.lib:
2>      Searching C:\lib\ampPhysics.lib:
2>      Searching C:\lib\physics.lib:
2>      Searching C:\lib\lua51.lib:
2>      Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\MSVCRT.lib:
2>      Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\OLDNAMES.lib:
2> 
2>  Finished searching libraries
2>protolib.obj : error LNK2001: unresolved external symbol __imp__NewtonCreateSphere
2>protolib.obj : error LNK2001: unresolved external symbol __imp__NewtonCreate
2>protolib.obj : error LNK2001: unresolved external symbol __imp__NewtonSetMemorySystem
2>protolib.obj : error LNK2001: unresolved external symbol __imp__NewtonBodySetUserData
2>protolib.obj : error LNK2001: unresolved external symbol __imp__NewtonBodyGetRotation
2>protolib.obj : error LNK2001: unresolved external symbol "class dMatrix __cdecl dGetIdentityMatrix(void)" (?dGetIdentityMatrix@@YA?AVdMatrix@@XZ)
2>protolib.obj : error LNK2001: unresolved external symbol __imp__NewtonBodySetForce
2>protolib.obj : error LNK2001: unresolved external symbol __imp__NewtonUpdate
2>protolib.obj : error LNK2001: unresolved external symbol __imp__NewtonBodyGetUserData
2>protolib.obj : error LNK2001: unresolved external symbol __imp__NewtonSetSolverModel
2>protolib.obj : error LNK2001: unresolved external symbol __imp__NewtonBodySetForceAndTorqueCallback
2>protolib.obj : error LNK2001: unresolved external symbol __imp__NewtonBodySetMaterialGroupID
2>protolib.obj : error LNK2001: unresolved external symbol __imp__NewtonBodySetMassProperties
2>protolib.obj : error LNK2001: unresolved external symbol __imp__NewtonBodySetTransformCallback
2>protolib.obj : error LNK2001: unresolved external symbol __imp__NewtonBodyGetMassMatrix
2>protolib.obj : error LNK2001: unresolved external symbol __imp__NewtonCreateDynamicBody
2>C:\Users\Thunder\Documents\projects\libproto framework\protolib\Release\protolib.exe : fatal error LNK1120: 16 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Alright, so that's not brilliant - from what I can tell it searches the libraries but it doesn't find any symbols within (I tried to build with just newton.lib but that didn't work so I added core, then physics, then ampPhysics to see if any of those had the symbols)
Notice how mondlicht.lib links cleanly (my fork of irrlicht) without error - unless newton is built with some combination of flags that must also be replicated on the destination project I'm quite at loss for why it's not linking, relevant steps to linking:

library directory:
C:\lib\

includes:

Code: Select all
#include <dMathDefines.h>
#include <dQuaternion.h>
#include <dVector.h>
#include <dMatrix.h>
#include <Newton.h>


includes
Code: Select all
#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))

//we're under some unix environment, put unix relevant preprocessor directives here if needed.

#else
   #if defined(_WIN32)

   //we're on windows, assuming visual studio - visual studio linkage is weird so we're doing it here.
   //terrible design, btw. preprocessor should never need to know this but that's VS for you.

   #pragma comment(lib, "newton.lib")
   #pragma comment(lib, "core.lib")
   #pragma comment(lib, "Mondlicht.lib")
   #pragma comment(lib, "ampPhysics.lib")
   #pragma comment(lib, "physics.lib")
   #pragma comment(lib, "lua51.lib")
   #pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
   #else

   //not windows or unix, put custom options here ploxxors.

   #endif
#endif



as for the rest of the code, it can be provided on request but I doubt it's a problem with the code - most of it is pretty standard.
LordHexahedron
 
Posts: 11
Joined: Sat Sep 03, 2016 10:05 pm

Re: problems linking under msvc 2013

Postby XycsoscyX » Thu Sep 22, 2016 2:37 pm

There is a full solution file under the projects directory (not the core_300 directory). That includes all the C++ libraries, as well as the base Newton libraries, and builds things as needed. There is included standard (lib?), dll, /MD, and /MT versions of all the projects (just like the core_300 projects have). If you want to build just Newton and make sure all dependencies are included, you should probably use that.

For the errors, it looks like you're not defining _NEWTON_STATIC_LIB before including Newton. I get the exact same linker errors when I build without defining that. I set it as a global define, but you should be able to define it anywhere, as long as it's defined before you include any Newton headers. the __imp__ calls are the mangled DLL names, but if you built a static library then the names will be different (not mangled like that).
XycsoscyX
 
Posts: 12
Joined: Wed Dec 15, 2004 2:46 am
Location: WA, USA

Re: problems linking under msvc 2013

Postby LordHexahedron » Thu Sep 22, 2016 3:43 pm

Well, I'll try using the solution - if I can find it.

I don't have a projects directory, only
applications
CMake
coreLibrary_300
packages

presumably you mean coreLibrary_300\projects\windows, which indeed contains vcxproj files for them all, there just isn't any solutions.

I'll try the static_md version, perhaps that one will work better - and if not I'll just see if I can add a global define for _NEWTON_STATIC_LIB in the vcxproj for newton.


as for defining _NEWTON_STATIC_LIB in my main application, that really ought to not be necessary but even if it is, it doesn't resolve the errors (implying that newton.vcxproj builds with incorrect flags, luckily that's ought to be trivial to fix)

UPDATE:
Ok, that didn't accomplish much of anything, added _NEWTON_STATIC_LIB to both projects ( properties>C/C++>preprocessor>preprocessor definitions ), still does not get rid of the linker errors - if anything this introduced more of them.

will try a few more things and report back results.

quick update before I go grab something to eath, after making a solution for core, newton, ampPhysics, and physics and building all with _NEWTON_STATIC_LIB I get more linker errors, but at least these aren't mangled.

Code: Select all
1>  Finished searching libraries
1>protolib.obj : error LNK2001: unresolved external symbol "class dMatrix __cdecl dGetIdentityMatrix(void)" (?dGetIdentityMatrix@@YA?AVdMatrix@@XZ)
1>core.lib(dgConvexHull4d.obj) : error LNK2001: unresolved external symbol _sched_yield
1>core.lib(dgDelaunayTetrahedralization.obj) : error LNK2001: unresolved external symbol _sched_yield
1>core.lib(dgAABBPolygonSoup.obj) : error LNK2001: unresolved external symbol _sched_yield
1>core.lib(dgPolygonSoupBuilder.obj) : error LNK2001: unresolved external symbol _sched_yield
1>physics.lib(dgWorldDynamicsParallelSolver.obj) : error LNK2001: unresolved external symbol _sched_yield
1>physics.lib(dgWorldDynamicsSimpleSolver.obj) : error LNK2001: unresolved external symbol _sched_yield
1>physics.lib(dgBodyMasterList.obj) : error LNK2001: unresolved external symbol _sched_yield
1>physics.lib(dgCollisionDeformableSolidMesh.obj) : error LNK2001: unresolved external symbol _sched_yield
1>physics.lib(dgMeshEffect5.obj) : error LNK2001: unresolved external symbol _sched_yield
1>physics.lib(dgMeshEffect3.obj) : error LNK2001: unresolved external symbol _sched_yield
1>physics.lib(dgCollisionConvexHull.obj) : error LNK2001: unresolved external symbol _sched_yield
1>physics.lib(dgBroadPhase.obj) : error LNK2001: unresolved external symbol _sched_yield
1>physics.lib(dgWorld.obj) : error LNK2001: unresolved external symbol _sched_yield
1>physics.lib(dgNarrowPhaseCollision.obj) : error LNK2001: unresolved external symbol _sched_yield
1>physics.lib(dgMeshEffect2.obj) : error LNK2001: unresolved external symbol _sched_yield
1>physics.lib(dgMeshEffect6.obj) : error LNK2001: unresolved external symbol _sched_yield
1>core.lib(dgThread.obj) : error LNK2001: unresolved external symbol _sched_yield
1>physics.lib(dgCollisionCompound.obj) : error LNK2001: unresolved external symbol _sched_yield
1>physics.lib(dgWorldDynamicUpdate.obj) : error LNK2001: unresolved external symbol _sched_yield
1>physics.lib(dgCollisionCompoundFractured.obj) : error LNK2001: unresolved external symbol _sched_yield
1>newton.lib(Newton.obj) : error LNK2001: unresolved external symbol _sched_yield
1>core.lib(dgPolyhedra.obj) : error LNK2001: unresolved external symbol _sched_yield
1>core.lib(dgThreadHive.obj) : error LNK2001: unresolved external symbol _sched_yield
1>core.lib(dgConvexHull3d.obj) : error LNK2001: unresolved external symbol _sched_yield
1>core.lib(dgThread.obj) : error LNK2001: unresolved external symbol _pthread_attr_init
1>core.lib(dgThread.obj) : error LNK2001: unresolved external symbol _pthread_attr_destroy
1>core.lib(dgThread.obj) : error LNK2001: unresolved external symbol _pthread_attr_setstacksize
1>core.lib(dgThread.obj) : error LNK2001: unresolved external symbol _pthread_create
1>core.lib(dgThread.obj) : error LNK2001: unresolved external symbol _pthread_join
1>core.lib(dgThread.obj) : error LNK2001: unresolved external symbol _pthread_setschedparam
1>core.lib(dgThread.obj) : error LNK2001: unresolved external symbol _pthread_getschedparam
1>core.lib(dgThread.obj) : error LNK2001: unresolved external symbol _sem_init
1>core.lib(dgThread.obj) : error LNK2001: unresolved external symbol _sem_destroy
1>core.lib(dgThread.obj) : error LNK2001: unresolved external symbol _sem_wait
1>core.lib(dgThread.obj) : error LNK2001: unresolved external symbol _sem_post
1>C:\Users\Thunder\Documents\projects\libproto framework\protolib\Release\protolib.exe : fatal error LNK1120: 13 unresolved externals


Also there's three fewer of them, if I'd have to guess I wager core.lib or physics.lib are the cause of nuking most of those.

based on the names it looks like some sort of threading library, it mentions pthreads but last I checked pthreads are a standard library.
LordHexahedron
 
Posts: 11
Joined: Sat Sep 03, 2016 10:05 pm

Re: problems linking under msvc 2013

Postby XycsoscyX » Thu Sep 22, 2016 4:20 pm

Ah, sorry, I meant the packages directory:

/newton-dynamics/packages/projects/visualStudio_201X(_dll, _static_md, _static_mt).

I'm actually using the _md projects in my engine. I've basically just included the projects, set the proper references, set the global define and viola.

I'm building for Windows on MSVC, but it seems like you might be trying to build for another target? You might need to track down what defines you have (in Newton and in your project), and what's getting set where. Make sure you're targeting MSVC and Windows, since afaik _sched_yield is for Linux?

The dGetIdentityMatrix error is because you're using the dNewton calls somewhere, but aren't including those. Those are all the C++ extensions over the basic C Newton core. dMath, in particular, is probably what you want to be building/linking against. If you look in the packages/projects directory, you can see the full build.sln (or just search for build.sln in your root Newton source directorty, there are a handful of them) and all the additional packages that it builds.
XycsoscyX
 
Posts: 12
Joined: Wed Dec 15, 2004 2:46 am
Location: WA, USA

Re: problems linking under msvc 2013

Postby LordHexahedron » Thu Sep 22, 2016 8:29 pm

building for win32, cross compiling with MSVC is painful enough that I'd sooner.. that's not appropriate so we'll leave it at that.

building packages/projects.. hey, there's a solution here - presumably with the correct globals defined by default.

thus far it seems ok enough, it built - but still won't link

Code: Select all
   //this would be one of every included project in the solution aside from tinyxml and dvisualdebuggerserver
   #pragma comment(lib, "dNewton.lib")
   #pragma comment(lib, "dAnimation.lib")
   #pragma comment(lib, "dContainers.lib")
   #pragma comment(lib, "dJointLibrary.lib")
   #pragma comment(lib, "dMath.lib")
   #pragma comment(lib, "dScene.lib")
   #pragma comment(lib, "physics.lib")
   #pragma comment(lib, "core.lib")
   #pragma comment(lib, "ampPhysics.lib")


We'll start with that, those are the built lib files

still getting:
1>protolib.cpp(126): warning C4244: 'argument' : conversion from 'double' to 'dFloat', possible loss of data
1>
1> Searching libraries
1> Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\msvcprt.lib:
1> Searching C:\lib\dNewton.lib:
1> Searching C:\lib\dAnimation.lib:
1> Searching C:\lib\dContainers.lib:
1> Searching C:\lib\dJointLibrary.lib:
1> Searching C:\lib\dMath.lib:
1> Searching C:\lib\dScene.lib:
1> Searching C:\lib\physics.lib:
1> Searching C:\lib\core.lib:
1> Searching C:\lib\ampPhysics.lib:
1> Searching C:\lib\Mondlicht.lib:
1> Searching C:\lib\lua51.lib:
1> Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\MSVCRT.lib:
1> Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\OLDNAMES.lib:
1> Searching C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x86\kernel32.lib:
1> Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\msvcprt.lib:
1> Searching C:\lib\dNewton.lib:
1> Searching C:\lib\dAnimation.lib:
1> Searching C:\lib\dContainers.lib:
1> Searching C:\lib\dJointLibrary.lib:
1> Searching C:\lib\dMath.lib:
1> Searching C:\lib\dScene.lib:
1> Searching C:\lib\physics.lib:
1> Searching C:\lib\core.lib:
1> Searching C:\lib\ampPhysics.lib:
1> Searching C:\lib\Mondlicht.lib:
1> Searching C:\lib\lua51.lib:
1> Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\MSVCRT.lib:
1> Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\OLDNAMES.lib:
1>
1> Finished searching libraries
1>protolib.obj : error LNK2001: unresolved external symbol _NewtonCreateSphere
1>protolib.obj : error LNK2001: unresolved external symbol _NewtonCreate
1>protolib.obj : error LNK2001: unresolved external symbol _NewtonSetMemorySystem
1>protolib.obj : error LNK2001: unresolved external symbol _NewtonBodySetUserData
1>protolib.obj : error LNK2001: unresolved external symbol _NewtonBodyGetRotation
1>protolib.obj : error LNK2001: unresolved external symbol _NewtonBodySetForce
1>protolib.obj : error LNK2001: unresolved external symbol _NewtonUpdate
1>protolib.obj : error LNK2001: unresolved external symbol _NewtonBodyGetUserData
1>protolib.obj : error LNK2001: unresolved external symbol _NewtonSetSolverModel
1>protolib.obj : error LNK2001: unresolved external symbol _NewtonBodySetForceAndTorqueCallback
1>protolib.obj : error LNK2001: unresolved external symbol _NewtonBodySetMaterialGroupID
1>protolib.obj : error LNK2001: unresolved external symbol _NewtonBodySetMassProperties
1>protolib.obj : error LNK2001: unresolved external symbol _NewtonBodySetTransformCallback
1>protolib.obj : error LNK2001: unresolved external symbol _NewtonBodyGetMassMatrix
1>protolib.obj : error LNK2001: unresolved external symbol _NewtonCreateDynamicBody
1>C:\Users\Thunder\Documents\projects\libproto framework\protolib\Release\protolib.exe : fatal error LNK1120: 15 unresolved externals


Perhaps those are functions deprecated since newton 2, since that's what I had available

for example:
Code: Select all
   NewtonSetMemorySystem(AllocMemory, FreeMemory);
   NewtonWorld* g_world = NewtonCreate();
   NewtonSetSolverModel(g_world, 1);
LordHexahedron
 
Posts: 11
Joined: Sat Sep 03, 2016 10:05 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 17 guests

cron