Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: LNK2019: unresolved external symbol  (Read 3755 times)

0 Members and 1 Guest are viewing this topic.

ADNS

  • Newbie
  • *
  • Posts: 3
    • View Profile
LNK2019: unresolved external symbol
« on: May 30, 2016, 08:50:10 am »
Hi, I've seen a lot of similar questions but I fail to fix it in my case.

I'm just trying to try SFML and as always I have problems with project configuration. I will be glad if you could help me.

Win 7 64bit, VS2010. SFML-2.3.2-windows-vc10-64-bit

C/C++>General>Additional Include Directories:
Code: [Select]
C:\Users\Suchy\Documents\Biblioteki\SFML-2.3.2-windows-vc10-64-bit\SFML-2.3.2\include;%(AdditionalIncludeDirectories)
Linker>General>Additional Include Directories:
Code: [Select]
C:\Users\Suchy\Documents\Biblioteki\SFML-2.3.2-windows-vc10-64-bit\SFML-2.3.2\lib;%(AdditionalLibraryDirectories)
Linker>Input>Additional Dependencies:
Code: [Select]
sfml-network-d.lib;sfml-system-d.lib;ws2_32.lib;%(AdditionalDependencies)
From tutorial I understand that if I want to use dll files I don't have to specify dependencies here (I only want to use network module) but I added it in an act of desperation. I also don't know what ws2_32 is. It's not placed in lib or bin folder . Is this uppose to be provided from some other sources?

In "debug" folder of my project I have following files copied from bin folder(those are the same files, removed "-2" just in case):
Code: [Select]
sfml-nerwork-d.dll,sfml-nerwork-d-2.dll, sfml-system-d.dll, sfml-system-d-2.dll
Code:
Code: [Select]
#include "stdafx.h"
#include <iostream>
#include <string>
#include <Windows.h>
#include <SFML\System.hpp>
#include <SFML\Network.hpp>

using namespace std;
//using namespace sf;


int _tmain(int argc, _TCHAR* argv[])
{
sf::TcpSocket socket;
return 0;
}

Output:
Code: [Select]
1>ClCompile:
1>  Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
1>  Copyright (C) Microsoft Corporation.  All rights reserved.
1> 
1>  cl /c /I"C:\Users\Suchy\Documents\Biblioteki\SFML-2.3.2-windows-vc10-64-bit\SFML-2.3.2\include" /ZI /nologo- /W3 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Yc"StdAfx.h" /Fp"Debug\xxx.pch" /Fo"Debug\\" /Fd"Debug\vc100.pdb" /Gd /TP /analyze- /errorReport:prompt stdafx.cpp
1>cl : Command line warning D9035: option 'nologo-' has been deprecated and will be removed in a future release
1> 
1>  stdafx.cpp
1>  Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
1>  Copyright (C) Microsoft Corporation.  All rights reserved.
1> 
1>  cl /c /I"C:\Users\Suchy\Documents\Biblioteki\SFML-2.3.2-windows-vc10-64-bit\SFML-2.3.2\include" /ZI /nologo- /W3 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Yu"StdAfx.h" /Fp"Debug\xxx.pch" /Fo"Debug\\" /Fd"Debug\vc100.pdb" /Gd /TP /analyze- /errorReport:prompt xxx.cpp
1>cl : Command line warning D9035: option 'nologo-' has been deprecated and will be removed in a future release
1> 
1>  xxx.cpp
1>Link:
1>  Microsoft (R) Incremental Linker Version 10.00.40219.01
1>  Copyright (C) Microsoft Corporation.  All rights reserved.
1> 
1>  "/OUT:C:\Users\Suchy\Documents\Visual Studio 2010\Projects\xxx\Debug\xxx.exe" /INCREMENTAL "/LIBPATH:C:\Users\Suchy\Documents\Biblioteki\SFML-2.3.2-windows-vc10-64-bit\SFML-2.3.2\lib" "sfml-network-d.lib" "sfml-system-d.lib" ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST "/ManifestFile:Debug\xxx.exe.intermediate.manifest" "/MANIFESTUAC:level='asInvoker' uiAccess='false'" /DEBUG "/PDB:C:\Users\Suchy\Documents\Visual Studio 2010\Projects\xxx\Debug\xxx.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT "/IMPLIB:C:\Users\Suchy\Documents\Visual Studio 2010\Projects\xxx\Debug\xxx.lib" /MACHINE:X86 Debug\xxx.exe.embed.manifest.res
1>  Debug\stdafx.obj
1>  Debug\xxx.obj
1>xxx.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::TcpSocket::~TcpSocket(void)" (__imp_??1TcpSocket@sf@@UAE@XZ) referenced in function _wmain
1>xxx.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::TcpSocket::TcpSocket(void)" (__imp_??0TcpSocket@sf@@QAE@XZ) referenced in function _wmain
1>C:\Users\Suchy\Documents\Visual Studio 2010\Projects\xxx\Debug\xxx.exe : fatal error LNK1120: 2 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:04.27
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: LNK2019: unresolved external symbol
« Reply #1 on: May 30, 2016, 03:36:49 pm »
Try to start with an empty project and follow the official tutorial step by step.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ADNS

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: LNK2019: unresolved external symbol
« Reply #2 on: May 31, 2016, 03:54:46 am »
I did this tutorial exactly step by step and indeed it works. But this doesn't solve my problem and I'm even more confused.

1. I've started project form template Visual C++>Win32 Project>Choosed "Console application" from wizard.
2. I did exactly what tutorial says.
3. I got an error:
Code: [Select]
error LNK1112: module machine type 'x64' conflicts with target machine type 'X86' c:\Users\Suchy\documents\visual studio 2010\Projects\SFML Test\SFML Test\sfml-graphics-d.lib(sfml-graphics-d-2.dll)So I go to project properties>Configuration Manager>Active solution platform>new:
Type or select new platform: x64
Copy setting from: Win32
Create new project platforms: true
>OK
-project compiles.
4. I've copied dll files to "..\porject directory\project name\x64\debug" folder of my project (usually I see .exe files there) but i sill got "dll missing" errors so i copied it also to "..\porject directory\project name\" and magically everthing works fine now.
5. I've linked newtwork module also and this works too.

Now I've got following additional questions:

q1. On downloads page it says
Quote
On Windows, choosing 32 or 64-bit libraries should be based on which platform you want to compile for, not which OS you have. Indeed, you can perfectly compile and run a 32-bit program on a 64-bit Windows. So you'll most likely want to target 32-bit platforms, to have the largest possible audience. Choose 64-bit packages only if you have good reasons.
First I thought "on which platform you want to compile for" means what is my actual system, regardles of what OS I'm using (I believe you can have 32bit OS on 64 computer) but now I uderstand it says about target OS version of my program. I know it's probably only my stupidity but without this "for" you could get it wrong... :P

q2. One time I have .exe files located at "..\porject directory\project name\bin\debug", another it's "..\porject directory\debug" what it depends on? In above procject I have seen that I acutally  don't have an .exe file under "..\porject directory\project name\x64\debug" but in "..\porject directory\debug".
Also how it works if I put dll files in "..\porject directory\project name" when I run it through VS (of course this does not work if I fire app from explorer without copying those files).

q3. Error I mentioned in step 3 says "c:\Users\Suchy\documents\visual studio 2010\Projects\SFML Test\SFML Test\sfml-graphics-d.lib(sfml-graphics-d-2.dll)" - how this works? There is no even such file in this folder.

g4. What oryginal(2019) error means. I've read this page https://msdn.microsoft.com/en-au/library/799kze2z.aspx but i still get no clue about his. Especially what is "(__imp_??1TcpSocket@sf@@UAE@XZ)" and where "_wmain" is defined?


Main problem stay. I want to incorporate this library to existing project. Not even the one I used in first post.
The target project will be DLL with different settings. So, what exactly have to/cannot be setup in order to work with this library? I don't want to create new project just to be able to use sockets in it.

Obviously I'm not very experienced in VS and C++ and some of my questions may seem stupid but if you have answer to any of them I will be happy.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: LNK2019: unresolved external symbol
« Reply #3 on: May 31, 2016, 08:27:07 am »
1. I've started project form template Visual C++>Win32 Project>Choosed "Console application" from wizard.
I always recommend to start with an empty project.

First I thought "on which platform you want to compile for" means what is my actual system, regardles of what OS I'm using (I believe you can have 32bit OS on 64 computer) but now I uderstand it says about target OS version of my program. I know it's probably only my stupidity but without this "for" you could get it wrong... :P
I guess one could change the wording a bit.

q2. One time I have .exe files located at "..\porject directory\project name\bin\debug", another it's "..\porject directory\debug" what it depends on?
Depends entirely on your VS project settings. In the end it doesn't matter where the executables are created at, you just need to know where and adapt accordingly.

q3. Error I mentioned in step 3 says "c:\Users\Suchy\documents\visual studio 2010\Projects\SFML Test\SFML Test\sfml-graphics-d.lib(sfml-graphics-d-2.dll)" - how this works? There is no even such file in this folder.
So there's no *.dll or ".lib file there?

g4. What oryginal(2019) error means. I've read this page https://msdn.microsoft.com/en-au/library/799kze2z.aspx but i still get no clue about his. Especially what is "(__imp_??1TcpSocket@sf@@UAE@XZ)" and where "_wmain" is defined?
The symbol is the mangled name of the sf::TcpSocket class and the error occurs because the application couldn't find the specific symbol.  _wmain or rather wmain is a Visual Studio specific main() function for Unicode characters. Such strange error usually mean that the project had been setup strangely, which is why I recommended to start from scratch.

Main problem stay. I want to incorporate this library to existing project. Not even the one I used in first post.
The target project will be DLL with different settings. So, what exactly have to/cannot be setup in order to work with this library? I don't want to create new project just to be able to use sockets in it.
Understand what (strange) changes you did to the project settings and adapt things accordingly. Since you have a custom setup it could be numerous things that could go wrong.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ADNS

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: LNK2019: unresolved external symbol
« Reply #4 on: May 31, 2016, 10:25:01 am »
Thanks for reply.

So there's no *.dll or ".lib file there?
As I said. Now I have .dll files there which I've copied manually but this error disappeared before I did this(just after I've changed the platform to x64).

Understand what (strange) changes you did to the project settings and adapt things accordingly. Since you have a custom setup it could be numerous things that could go wrong.

I believe this mean there is no step by step quide/list of what should be checked?
I'm not 100% sure (I did this long time ago) but the project from first post was created with"win32 console application". From tutorial I understand that this should be valid template. I usually don't change any settings as long as everything works. Headers are visible, linker clearly can find .lib files. I have no other idea what to do. I guess I should learn what this linker does in background...