Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unresolved symbol error visual studio 2017 #170

Open
Gunlek opened this issue Jan 13, 2018 · 5 comments
Open

Unresolved symbol error visual studio 2017 #170

Gunlek opened this issue Jan 13, 2018 · 5 comments

Comments

@Gunlek
Copy link

Gunlek commented Jan 13, 2018

Everytime i try to compile with visual studio 2017, i'm getting in trouble with an unresolved symbol error (LNK2019)... How can I fix that ?

@wjwwood
Copy link
Owner

wjwwood commented Jan 13, 2018

Please post the full build output, without it there is no context for me to deduce what the issue might be.

@Gunlek
Copy link
Author

Gunlek commented Jan 14, 2018

Of course, here's the build output I get:

1>------ Début de la génération : Projet : SerialTest, Configuration : Debug x64 ------
1>Main.obj : error LNK2019: unresolved external symbol "class std::vector<struct serial::PortInfo,class std::allocator<struct serial::PortInfo> > __cdecl serial::list_ports(void)" (?list_ports@serial@@YA?AV?$vector@UPortInfo@serial@@V?$allocator@UPortInfo@serial@@@std@@@std@@XZ) referenced in main function
1>PATH_TO_PROJECT\x64\Debug\SerialTest.exe : fatal error LNK1120: 1 externes non résolus
1>Génération du projet "SerialTest.vcxproj" terminée -- ÉCHEC.
========== Génération : 0 a réussi, 1 a échoué, 0 mis à jour, 0 a été ignoré ==========

I'm french and so, output is french, I translated errors in english for you

@wjwwood
Copy link
Owner

wjwwood commented Jan 15, 2018

Thanks, typically, this kind of error will occur when either you have not linked against the serial library (not sure how to express that in Visual Studio) or in this specific linker error perhaps you're building serial.cc yourself, but have excluded the "list_ports" part of the library.

@klukander
Copy link

Hi, I ran into this with VS2019 and banged my head against the wall for quite some time with the typical visual studio linking things all in order. I then noticed that this happens with two functions in serial requiring registry access:

Error LNK2019 unresolved external symbol __imp_RegCloseKey referenced in function "class std::vector<struct serial::PortInfo,class std::allocator > __cdecl serial::list_ports(void)" (?list_ports@serial@@ya?AV?$vector@UPortInfo@serial@@v?$allocator@UPortInfo@serial@@@std@@@std@@xz)

Error LNK2019 unresolved external symbol __imp_RegQueryValueExW referenced in function "class std::vector<struct serial::PortInfo,class std::allocator > __cdecl serial::list_ports(void)" (?list_ports@serial@@ya?AV?$vector@UPortInfo@serial@@v?$allocator@UPortInfo@serial@@@std@@@std@@xz)

And then from a random stackoverflow response I already lost, found out that these need to be linked against
Advapi32.lib

Adding that to my project's linked libraries seems to solve the issue.

I have no previous experience on this, and I don't quite understand why compiling the serial library itself, and the test_serial project included don't have an issue with this (the test runs fine).

@Charlie-Gallie
Copy link

Charlie-Gallie commented Jun 3, 2024

Apologies to add to such an old thread, but if anybody else encounters this issue even with the files included in your project and linked to Advapi32.lib, try changing the .cc file extensions to .cpp.

My version of Visual Studio doesn't compile .cc files by default. Changing them to .cpp fixed it.

An alternative issue which can sometimes cause the same symptoms is if you have two .cpp/.cc files with the same name, e.g., serial.cc (the one this library uses) and Serial.cpp (your serial interface for your own project). Case sensitivity isn't always a thing, so try renaming your implementation to something different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants