lnk2001 error in VS trying to use the Bullet physics library - c++

I'm new to C++, Visual Studio (2019) and Bullet (2.89).
I've been tying to build the Hello_World.cpp from Bullet for the past few days but I'm stuck on these 5 linking errors:
1>Hello_World.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall btCollisionShape::getBoundingSphere(class btVector3 &,float &)const " (?getBoundingSphere#btCollisionShape##UBEXAAVbtVector3##AAM#Z)
1>Hello_World.obj : error LNK2001: unresolved external symbol "public: virtual float __thiscall btCollisionShape::getAngularMotionDisc(void)const " (?getAngularMotionDisc#btCollisionShape##UBEMXZ)
1>Hello_World.obj : error LNK2001: unresolved external symbol "public: virtual float __thiscall btCollisionShape::getContactBreakingThreshold(float)const " (?getContactBreakingThreshold#btCollisionShape##UBEMM#Z)
1>Hello_World.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall btConvexShape::project(class btTransform const &,class btVector3 const &,float &,float &,class btVector3 &,class btVector3 &)const " (?project#btConvexShape##UBEXABVbtTransform##ABVbtVector3##AAM2AAV3#3#Z)
1>Hello_World.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall btSphereShape::calculateLocalInertia(float,class btVector3 &)const " (?calculateLocalInertia#btSphereShape##UBEXMAAVbtVector3###Z)
There are other people who had this or a similar problem but got no answer or it didn't work for me.
setup:
I used premake to set up the VS solution, Bullet is organized in static Libraries (as projects with source code that gets compiled to lib files) and I am now trying to link them with an application-project.
all projects are using static linking (for debug).
I've referenced all bullet projects to my project.
I've even staticly linked to the lib files from bullet (and the linker can apparently see these files, I even tried giving the absolute path)
As far as I can tell the functions exist and have the same signature in the .cpp and .h files
If you need more details let me know.
(One lead I possibly got is something about different bt_double_precision? But that might not be it and the only think I could find was floating point model using different precision. But making that the same didn't do anything)
Thanks in advance!
EDIT:
I don't think this answer applies to me
What is an undefined reference/unresolved external symbol error and how do I fix it?
EDIT:
Maybe worth mentioning: The file structure of the project is really weird (dictated by premake):
solution and project files are in: bullet3-2.89\build3\vs2010
high level header files(these are the ones used by Hello_World that include other headers): bullet3-2.89\src
source and header files are subdirectories of bullet3-2.89\src
libraries: bullet3-2.89\bin
but all headers use the correct relative paths in their include and I have set the project's include and library directories to those locations

I found a workaround. Just gonna hijack one of the example projects from Bullet and use that instead. They seem to be better at VS settings than me :D
Anyway, thanks for your suggestions.

Had the same issue where just a few of the functions didn't link.
This is most likely due to the Bullet library being built with BT_USE_DOUBLE_PRECISION, meaning all btScaler will be of type double.
But the library is included without BT_USE_DOUBLE_PRECISION, meaning the program will try to link with the float versions of the functions.
But they don't exists since the built version uses doubles.

Related

XDispatch C++ Unresolved Externals

I'm work with GCD in C++ with xdisptach, libdispatch in Visual Studio 2012 on Windows 7.
I am declaring a class with a global variable that is a dispatch queue. Other functions in the class call the queue's function. Everything compiles fine, except when i instantiate the queue in the constructor.
xdispatch::queue* dispatch_queue;
AsyncNode()
{
dispatch_queue = new xdispatch::queue(Name);
}
When dispatch_queue = new xdispatch::queue(Name); is commented out, it all compiles fine. Otherwise i get the following errors.
Error 50 error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall xdispatch::queue::~queue(void)" (__imp_??1queue#xdispatch##UAE#XZ) referenced in function "public: virtual void * __thiscall xdispatch::queue::`scalar deleting destructor'(unsigned int)" (??_Gqueue#xdispatch##UAEPAXI#Z)
Error 49 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall xdispatch::queue::queue(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0queue#xdispatch##QAE#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "public: __thiscall AsyncNode::AsyncNode(void)" (??0AsyncNode##QAE#XZ)
Error 53 error LNK2001: unresolved external symbol "public: virtual void __thiscall xdispatch::object::resume(void)" (?resume#object#xdispatch##UAEXXZ)
Error 51 error LNK2001: unresolved external symbol "public: virtual void * __thiscall xdispatch::queue::native(void)const " (?native#queue#xdispatch##UBEPAXXZ)
Error 52 error LNK2001: unresolved external symbol "public: virtual struct dispatch_queue_s * __thiscall xdispatch::queue::native_queue(void)const " (?native_queue#queue#xdispatch##UBEPAUdispatch_queue_s##XZ)
This is the main site for xdispatch, but i can't find anything in terms of a forum or help with xdispatch in particular. There are many for objective-c.... :/
http://opensource.mlba-team.de/xdispatch/docs/current/index.html
First of all, the behavior regarding deleting the "problematic" line is normal - when you're defining a pointer you're not invoking any function, and that is the reason you are not getting the "unresolved external errors".
When you're initializing the variable by calling the constructor, you then run into problems because you're trying to call a function which is not available at link time.
When working with external libraries using DLLs, you must link to the appropriate import libraries, usually supplied as "lib" files. In your case, there is a folder named "lib" in the zip package. Also, the DLLs must availble at run-time - by putting them in the folder of the executable, or adding them to the PATH environment variable.
In order to link to a library, follow these steps (taken from MSDN):
Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.
Click the Linker folder.
Click the Input property page.
Modify the Additional Dependencies property.

How to use class from a different project in C++ with Qt?

There's this class MailHandler in the solution MailTest, which I use to send signals to the class MailCom in the solution MailResponse. My problem revolves around creating an object of the MailHandler class in the MailCom class, which is in a different project, and doing operations from here. What is the most efficient way of establishing the connection without modifying the MailTest project into a lib or DLL?
I need to link with a correct path, but I'm not sure at which settings are important in this case. This is the current error I'm getting when trying to instantiate the MailHandler object:
1> Creating library ..\..\bin\pvc6d.lib and object ..\..\bin\pvc6d.exp
1>CMailCom.obj : error LNK2019: unresolved external symbol "public: class QStringList __thiscall MailHandler::ReturnAllFunctions(void)" (?ReturnAllFunctions#MailHandler##QAE?AVQStringList##XZ) referenced in function "public: __thiscall pvc::hardwarecom::CMailCom::CMailCom(class pvc::data::CData &,class pvc::data::CRudderServo *,class pvc::data::CPropulsionManager *,class QGraphicsScene *)" (??0CMailCom#hardwarecom#pvc##QAE#AAVCData#data#2#PAVCRudderServo#42#PAVCPropulsionManager#42#PAVQGraphicsScene###Z)
1>CMailCom.obj : error LNK2019: unresolved external symbol "public: __thiscall MailHandler::MailHandler(class QObject *)" (??0MailHandler##QAE#PAVQObject###Z) referenced in function "public: __thiscall pvc::hardwarecom::CMailCom::CMailCom(class pvc::data::CData &,class pvc::data::CRudderServo *,class pvc::data::CPropulsionManager *,class QGraphicsScene *)" (??0CMailCom#hardwarecom#pvc##QAE#AAVCData#data#2#PAVCRudderServo#42#PAVCPropulsionManager#42#PAVQGraphicsScene###Z)
1>..\..\bin\pvc6d.exe : fatal error LNK1120: 2 unresolved externals
If you want to use a class of a external project, you can try to #include its header file (MailHandler.h, MailHandler.hxx etc.). I assume thats what you did. Obviously there is also a according source file (MailHandler.cpp, MailHandler.cxx). You can try to add this file to your current project. If you are lucky it compiles and links and your unresolved externals go away. More likely the source file has other dependencies and does not compile/link right away.
This is rather a hack - not a robust long term solution.
It's better to copy the file with its dependencies into your project
It's best to extract the needed classes in a separate project (i.e creating a lib or dll) that your project and that the other solution 'MailTest' are using as a independent client.
You are missing the correct libraries. The linker does not know about the functions called, add LIBS += -Lpath/to/lib -lthelib to your pro file.

Trying to use my project with external opencv

I'm attaching some external libraries to my project in C++.
These libraries make use of the opencv2 libraries.
I already added the opencv2 include files to my c/c++ properties. I also added all the relevant lib files which I googled and found to the Linker input list. (I'm running the release version, but I also tried the debug version with the "d" extension).
opencv_core230.lib
opencv_highgui230.lib
opencv_objdetect230.lib
opencv_imgproc230.lib
opencv_ml230.lib
opencv_legacy230.lib
opencv_video230.lib
I'm getting these 4 annoying linking problems regarding the setSVMDetector#HOGDescriptor.
I looked everywhere for a solution and couldn't find one.; no one really uses the setSVM function in the external program.
Here are the linking problems:
Error 14 error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::HOGDescriptor::setSVMDetector(class cv::_InputArray const &)" (?setSVMDetector#HOGDescriptor#cv##UAEXABV_InputArray#2##Z) C:\Users\idan\Documents\Visual Studio 2010\GraspTestingTool\GraspTestingTool\GraspTestingTool.obj GraspTestingTool
Error 15 error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::HOGDescriptor::setSVMDetector(class cv::_InputArray const &)" (?setSVMDetector#HOGDescriptor#cv##UAEXABV_InputArray#2##Z) C:\Users\idan\Documents\Visual Studio 2010\GraspTestingTool\GraspTestingTool\htmlGenerator.obj GraspTestingTool
Error 16 error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::HOGDescriptor::setSVMDetector(class cv::_InputArray const &)" (?setSVMDetector#HOGDescriptor#cv##UAEXABV_InputArray#2##Z) C:\Users\idan\Documents\Visual Studio 2010\GraspTestingTool\GraspTestingTool\sequenceTests.obj GraspTestingTool
Error 17 error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::HOGDescriptor::setSVMDetector(class cv::_InputArray const &)" (?setSVMDetector#HOGDescriptor#cv##UAEXABV_InputArray#2##Z) C:\Users\idan\Documents\Visual Studio 2010\GraspTestingTool\GraspTestingTool\Utilities.obj GraspTestingTool
Does anyone know how to solve this issue?
Thanks a lot!
Error is due to not adding specifice library in debug or releas mode.
use 32 bit or 64 library depending on your target machine
Add respective library of opencv in release mode -
opencv_core242.lib opencv_highgui242.lib opencv_imgproc242.lib opencv_ml242.lib
opencv_legacy242.lib opencv_video242.lib
OR If you want run program in debug mode then
use debug lib of opencv
opencv_core220d.lib
opencv_highgui220d.lib
opencv_video220d.lib
opencv_ml220d.lib
opencv_legacy220d.lib
opencv_imgproc220d.lib
opencv_objdetect242.lib
C:\opencv\build\x86\vc10\lib
Add the library file "opencv_objdetect248.lib; opencv_objdetect248d.lib;" in Project roperties-->Linker-->Input.
You need to add opencv_objdetect library. If you using debug mode add objdetect(version)d.lib, however, if you release mode add objdetect(version).lib

I have a third party lib, I have error LNK2019: unresolved external ... How to investigate to fix it

I have a third party libs. (msvc10) a MT/MD (Static cfgs's) and dynamic DLL cfg.
I have qt + msvc10 express + win sdk.7
Ok , I use the existing examples offered, (using the libs) I can't compile ..... I have 4 unresolved external errors of the same lib.
(But I have zero errors for the others)
I have not support for these lib...... (but they are legal, I am a member without rights)
Which are the steps to investigate a possible fix? Where I have to look ?
Thanks.
Edit 1:
The errors was:
TD_ExamplesCommon.lib(ExHostAppServices.obj) : error LNK2019: unresolved external symbol __imp__RegEnumValueW#32 referenced in function "public: virtual bool __thiscall ExHostAppServices::ttfFileNameByDescriptor(class OdTtfDescriptor const &,class OdString &)" (?ttfFileNameByDescriptor#ExHostAppServices##UAE_N ABVOdTtfDescriptor##AAVOdString###Z)
TD_ExamplesCommon.lib(ExHostAppServices.obj) : error LNK2019: unresolved external symbol __imp__RegCloseKey#4 referenced in function "public: virtual bool __thiscall ExHostAppServices::ttfFileNameByDescriptor(class OdTtfDescriptor const &,class OdString &)" (?ttfFileNameByDescriptor#ExHostAppServices##UAE_N ABVOdTtfDescriptor##AAVOdString###Z)
TD_ExamplesCommon.lib(ExHostAppServices.obj) : error LNK2019: unresolved external symbol __imp__RegQueryValueExW#24 referenced in function "public: virtual bool __thiscall ExHostAppServices::ttfFileNameByDescriptor(class OdTtfDescriptor const &,class OdString &)" (?ttfFileNameByDescriptor#ExHostAppServices##UAE_N ABVOdTtfDescriptor##AAVOdString###Z)
TD_ExamplesCommon.lib(ExHostAppServices.obj) : error LNK2019: unresolved external symbol __imp__RegOpenKeyExW#20 referenced in function "public: virtual bool __thiscall ExHostAppServices::ttfFileNameByDescriptor(class OdTtfDescriptor const &,class OdString &)" (?ttfFileNameByDescriptor#ExHostAppServices##UAE_N ABVOdTtfDescriptor##AAVOdString###Z)
..\exe\OdaQtApp.exe : fatal error LNK1120: 13 unresolved externals
During this post I have received a solution: I have to link with Advapi32.lib...
My question is : how can I know this ?
I have tried the dependencyywalker, but it cant use the .lib's....
During this post I have received a solution: I have to link with Advapi32.lib... My question is : how can I know this?
When you get an "unresolved external" error from the linker, that means that it was looking for a match for a function or variable name that some object file needs and the linker was unable to find that name defined in one of the object files or libraries.
Start by looking at the first of these errors (I've reformatted it a bit to make it slightly more readable - I encourage yo to do the same next time you come across one of these):
TD_ExamplesCommon.lib(ExHostAppServices.obj) : error LNK2019: unresolved external symbol
__imp__RegEnumValueW#32 referenced in function
"public: virtual bool __thiscall ExHostAppServices::ttfFileNameByDescriptor(
class OdTtfDescriptor const &,class OdString &)"
(?ttfFileNameByDescriptor#ExHostAppServices##UAE_N ABVOdTtfDescriptor##AAVOdString###Z)
There's a lot of stuff in that error message (much of it may look like garbage). Fortunately, much of it can be ignored in most cases. The most important item is that the linker is looking for the symbol __imp__RegEnumValueW#32 The name has some gunk on it, but fortunately it's pretty recognizable anyway.
the __imp__ prefix indicates it's looking for a DLL import. In nearly all cases that can be ignored for your purposes.
the #32 suffix is something the Microsoft compiler adds to function names for certain calling conventions. It's also generally not important for your purposes (for the record it indicates that the function expects 32 bytes of argument data)
So we're left with the fact that the linker is looking for RegEnumValueW. That looks a lot like the name of a Win32 API.
If you look at the docs for RegEnumValueW (or RegEnumValue, since many Win32 APIs have both an A and a W variant to handle ANSI/UNICODE builds) we'll find in the documentation this bit of information:
Requirements
Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
Header Winreg.h (include Windows.h)
>> Library Advapi32.lib
DLL Advapi32.dll
Unicode and ANSI names RegEnumValueW (Unicode) and
RegEnumValueA (ANSI)
That's how you know you need advapi32.lib.
So in the future, when you get an "unresolved external" error from the linker, just ignore most of the gunk in the error message and concentrate on the symbol it says it can't find - that should lead you to the library, object file or other item you might be missing.
Just for the record, advapi32.lib will be needed by most Windows applications of any complexity.
you can try to use dependencywalker to see the list of dependencies for your dlls and see what it's missing.
have you entered the *.lib file in the linker options? (input --> additional dependencies"), and in addition the path to the .lib in libraries directories option?

linking error with CMake and Visual Studio 2010

I'm trying to compile osgearth library with VS2010. The library uses CMake, so after setting all dependencies it generates a VS2010 solution file. However when running build in VS I get this linker error (and 200 similar ones)
Error 7 error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::basic_ofstream >::`vbase destructor'(void)" (_imp??_D?$basic_ofstream#DU?$char_traits#D#std###std##QAEXXZ) referenced in function "public: virtual void __thiscall osgEarth::DiskCache::setImage(class osgEarth::TileKey const &,struct osgEarth::CacheSpec const &,class osg::Image const *)" (?setImage#DiskCache#osgEarth##UAEXABVTileKey#2#ABUCacheSpec#2#PBVImage#osg###Z) C:\swproj\osgearth-src\src\osgEarth\Caching.obj osgEarth
I'm not very familiar with C++, is there anything else I have to set up?
You're missing a reference to std::ofstream. You either need an #include in one of your files or a reference to the standard library dll in your project.