I have linker errors about functions don't even exist. I have no idea what's going on here. Code is in this GitHub repo.
I have these linker errors:
1>sort.ixx.obj : error LNK2019: unresolved external symbol "void __cdecl words::swap(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> > > > > &,unsigned __int64,unsigned __int64)" (?swap@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@@_K1@Z::<!words>) referenced in function "void __cdecl words::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> > > > > &,unsigned __int64,unsigned __int64)" (?sort@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@@_K1@Z::<!words>)
1>utils.ixx.obj : error LNK2019: unresolved external symbol "unsigned __int64 __cdecl words::max_word_length(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> > > > > const &)" (?max_word_length@Godherald"Words".CosmicTraveler @@YA_KAEBV?$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>) referenced in function "void __cdecl words::show_words(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> > > > > const &)" (?show_words@Godherald"Words".CosmicTraveler @@YAXAEBV?$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>)
1>E:\programming\visual_studio_2019\Projects\beginningcpp20\chapter11ex5\x64\Debug\chapter11ex5.exe : fatal error LNK1120: 2 unresolved externals
I created an empty project and added the code to it. Would someone please help me with these errors? Thanks.
Edit for clarification and some more info: I'm using VS Community 2022.
And the functions words::max_word_length
and words::swap
weren't declared anywhere, since the functions I declared with those names are actually declared outside the words
namespace rather than inside. The stupid thing is trying to look for definitions of functions that aren't even declared anywhere, hence me saying I have linker errors about functions that don't exist. I hope that clears things up.
This is the snippet I modified for your reference. It is not a good idea to put two function definitions from different modules into one cpp file.
internals.cpp:
Why do we need to put both
import words:sort;
andimport words;
? And also, again, why are there linker errors aboutwords::max_word_length
andwords::swap
which are functions that weren't even declared?Also, they're functions defined in implementation files for interface partitions of the same module.
The original exercise asks to create a module implementation partition called internals. But it doesn't seem like it's possible to do that.
linker errors: the compiler did not find the relevant module implementation unit
module words:sort;
ormodule words:utils;
(not import words:sort;).export import :alias
uesd in two ixx files,module words:sort;
can also be changed tomodule words:alias;
.Since it involves the implementation principle of the module, I suggest you post a new issue on the Q&A platform.
Hi, @Osman Zakir
May I know if your code can be complied well now?
Sign in to comment