Unresolved External Symbol in project

208 views
Skip to first unread message

Daniel Zhan

unread,
Jan 20, 2024, 2:08:15 PM1/20/24
to ProjectChrono
Hi all,

I've working on a simulation using Project Chrono - it's an old simulation that someone else completed in 2018 using a presumably older version of Chrono. I'm using Windows 11, Visual Studio 2022 and cmake to build the project, and using the most up-to-date version of Chrono to continue working on said project. 

When attempting to build the project, I'm getting linker errors (unrecognized external symbol) in Visual Studio Code, specifically:

LNK2019 unresolved external symbol "__declspec(dllimport) public: static void * __cdecl chrono::ChFrame<double>::operator new(unsigned __int64)" (__imp_??2?$ChFrame@N@chrono@@SAPEAX_K@Z) referenced in function "class std::shared_ptr<class chrono::ChBodyEasyBox> __cdecl chrono_types::make_shared<class chrono::ChBodyEasyBox,double &,double &,double &,double,bool,bool,class std::shared_ptr<class chrono::ChMaterialSurfaceSMC> &,0>(double &,double &,double &,double &&,bool &&,bool &&,class std::shared_ptr<class chrono::ChMaterialSurfaceSMC> &)" (??$make_shared@VChBodyEasyBox@chrono@@AEANAEANAEANN_N_NAEAV?$shared_ptr@VChMaterialSurfaceSMC@chrono@@@std@@$0A@@chrono_types@@YA?AV?$shared_ptr@VChBodyEasyBox@chrono@@@std@@AEAN00$$QEAN$$QEA_N2AEAV?$shared_ptr@VChMaterialSurfaceSMC@chrono@@@2@@Z)

This error shows a linking problem in that the program could not find the new operator in ChFrame. I have 3 other errors denoting linker problems with the delete operator for ChFrame, along with the new and delete operators for ChLinkLock. I'm wondering if the source files in Project Chrono have since changed to no longer support these operators or if there's something wrong with how I built the project.

Best,
Daniel

Dario Mangoni

unread,
Jan 20, 2024, 6:47:30 PM1/20/24
to Daniel Zhan, ProjectChrono
Hi Daniel,
Indeed many things changed especially in the recent past, so it's a great time to update old code. 

It's surely better to look directly to the code instead of the error only, but I would recommend to check few things:

- call SetCollisionSystemType on your ChSystem (if you have contacts) 
- please mind that the order and number of arguments of ChEasyBody changed
- all the visual and collision shape changed
- the way the ChSurfaceMaterial is passed to the bodies changes

I would recommend you to check the docs


And the Changelog in the repo! 





-------- Messaggio originale --------
Da: Daniel Zhan <dzh...@gmail.com>
Data: 20/01/24 20:08 (GMT+01:00)
A: ProjectChrono <projec...@googlegroups.com>
Oggetto: [chrono] Unresolved External Symbol in project

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/2e8da663-45f5-416d-a1fd-a9e8eb2ff88dn%40googlegroups.com.

Daniel Zhan

unread,
Jan 22, 2024, 10:29:46 PM1/22/24
to ProjectChrono
Hi all,

I believe I was able to narrow the bug down to this line (among other similar ones) (this bug shows upon attempting to build):
auto object = chrono_types::make_shared<ChBodyEasyBox>(length, width, height, 100.0, true, true, material);

I made sure the arguments are of the correct types to initialize the object with a matching constructor, but still encounter error LNK2019. I am fairly certain the chrono_types::make_shared<> shared pointer constructor is working, as there are other objects in the source code using this same code that do not produce a LNK2019 error (or any other error). This leads me to believe that it is unlikely that I have linked my libraries improperly.

When I try using std::make_shared rather than chrono_types::make_shared, I only encounter a LNK2019 error with the delete operator, whereas using chrono_types::make_shared gives me two LNK2019 errors, involving the new and delete operators.

Best,
Daniel

Radu Serban

unread,
Jan 23, 2024, 3:39:38 AM1/23/24
to ProjectChrono

Hi Daniel,

 

Just to clarify:

  1. Do you have any linking errors when building the Chrono libraries and demos?
  2. Or does this only happen when you build your project (and link to a build or install Chrono tree)?

 

In either case, please

  • Send the corresponding CMakeCache.txt file.
  • Enable CMAKE_VERBOSE_MAKEFILE, rebuild, and post the complete output for the compiling/linking command that results in errors.

 

If the problem is #2 above, could you please try to clone the chrono-projects repository (https://github.com/projectchrono/chrono-projects), then configure and build it to see if you also encounter issues? That repository assumes you have Chrono already built (you only need to specify where the Chrono CMake project configuration script is located); there are several projects in there, but only those that use Chrono modules that you had enabled will be configured and built.

 

Thanks,
Radu

Daniel Zhan

unread,
Jan 23, 2024, 9:30:37 AM1/23/24
to ProjectChrono
Hi all,

I was able to resolve the issue by rebuilding chrono using the release version on github rather than the contents of main branch - thanks.

Best,
Daniel

Radu Serban

unread,
Jan 23, 2024, 9:57:50 AM1/23/24
to ProjectChrono

Daniel – that is not a solution.  The latest release (8.0) is almost one year old. There were many changes in the main branch, and these will be the object of a new release soon.

It’d be really useful to understand why you were getting these linking problems.  Could you please provide the answers to the questions below?

 

--Radu

Daniel Zhan

unread,
Apr 10, 2024, 10:28:28 PM4/10/24
to ProjectChrono
Hi Radu,

Sorry for the long wait. This only happens when I build my project. When I build the same chrono_projects on github, they work properly. I've attached my CMakeCache.txt and pasted one of the errors below - all 9 look similar to that, although with different classes.

Error LNK2019 unresolved external symbol "__declspec(dllimport) public: static void * __cdecl chrono::ChFrame<double>::operator new(unsigned __int64)" (__imp_??2?$ChFrame@N@chrono@@SAPEAX_K@Z) referenced in function "class std::shared_ptr<class chrono::ChBodyEasyBox> __cdecl chrono_types::make_shared<class chrono::ChBodyEasyBox,float &,float &,float &,double,bool,bool,0>(float &,float &,float &,double &&,bool &&,bool &&)" (??$make_shared@VChBodyEasyBox@chrono@@AEAMAEAMAEAMN_N_N$0A@@chrono_types@@YA?AV?$shared_ptr@VChBodyEasyBox@chrono@@@std@@AEAM00$$QEAN$$QEA_N2@Z) bichir C:\Users\dzhan\Desktop\chrono\bichir\build\bichir.obj

Best,
Daniel
CMakeCache.txt
Message has been deleted

Radu Serban

unread,
Apr 13, 2024, 3:11:51 AM4/13/24
to ProjectChrono

Daniel – unless we can reproduce the issue, I don’t see how we could help.  Since this only happens with your own code, you will need to provide us with a minimal reproducible example.

Reply all
Reply to author
Forward
0 new messages