I'm Getting A Linker Error Even Though I've Defined the Function In Question
I have this exercise solution for a C++20 book I'm reading for which I have a linker error. Code Gist.
1>chapter11ex3.obj : error LNK2019: unresolved external symbol "void __cdecl words::sorting::sort(class std::vector<class std::shared_ptr<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<class std::shared_ptr<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > > &)" (?sort@sorting@Godherald"Words".CosmicTraveler @@YAXAEAV?$vector@V?$shared_ptr@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@std@@V?$allocator@V?$shared_ptr@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@std@@@2@@std@@@Z::<!words.sorting>) referenced in function main
1>E:\programming\visual_studio_2019\Projects\beginningcpp20\chapter11ex3\x64\Debug\chapter11ex3.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "chapter11ex3.vcxproj" -- FAILED.
I have the function defined properly so why is this linker error here? Someone please help me out here. Thanks.
I haven't tried it with other IDEs and compilers yet, but could it be a problem with just VS? I'm using VS2022. There's also a notification in the "Output" on startup that says that IntelliSense support for C++20 Modules is experimental.
What I did was just try to build the code in Debug mode under x64 configuration. I'm trying to build under /std:c++latest mode with Modules on, and the settings to scan sources for module dependencies and multi-processor compilation are both turned on as well. I didn't touch anything else in Project Settings.
Using VS2019 (16.11.9) source code was loaded into an empty project. Build for x64 debug completed without errors.
Did you try in VS2022? Since that's the version under which it fails with a linker error for me. Could be problem with the 2022 version. I'll reinstall VS2019 and try it with that one.
I tested the code in VS 2022 and built successfully.
What did you do? Should I post my build environment info so you can see what I may have done wrong?
I created empty console project （x64 debug）to load source code.
All default settings except for the settings mentioned above
Worked for me too, just now. But the first time I tried to do that, I got that linker error.
The C++20 book I'm reading also has an exercise that says to create a module implementation partition. The project I tried to build for that exercise fails to build. In VS2022, I get an error saying that the partition can't be found. Does Visual Studio not support implementation partitions? And if not, does the standard not talk about them at all?
Sign in to comment
Sort by: Most helpful
Yeah, thanks. It builds for me in VS2019 as well. So it really seems to be a problem with VS2022. I hope it gets addressed soon.
I tried posting this as an answer, but for some reason it won't go through.
Sign in to comment