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

Author Topic: [SOLVED] Visual Studio Linker Errors (out of nowhere)  (Read 1565 times)

0 Members and 1 Guest are viewing this topic.

Rowvan

  • Newbie
  • *
  • Posts: 2
    • View Profile
[SOLVED] Visual Studio Linker Errors (out of nowhere)
« on: August 25, 2023, 05:00:51 am »
Hello!

Before you get mad and think "oh brother, another guy with probably the SAME linker error", i have been working with SFML for about a week now. I ran into a few linker errors as everyone does, but found my ways to fix them. Today, I was working on a project (whole reason I'm using SFML) and i compiled with a few changes in debug mode and all the sudden got 6 unresolved externals.. so, of course, i remove the changes. Still linker errors. No idea what to do here, super confused.

Timeline:
 - 4+ hours of working on this project (no problems)
 - 1 minor tweak (laterally changed a value to change the way an SFML circle turned different colors, a change now that is deleted)
 - I compile and... bam! linker issues..
 - Delete 3 lines of (aforementioned) changes
 - Still linker issues

I never closed Visual Studio nor modified anything but code. I have since closed + reopened it. No dice.

Here is some more info for confirmation:
I am dynamically linking, will migrate to static when Im ready (only havent because of security reasons)
[ALL CONFIG PROPERTIES WINDOW]
C++ -> General -> Additional Include Dirs: E:\SFML\include;%(AdditionalIncludeDirectories)
Linker -> General -> Additional Lib Dependencies: E:\SFML\lib;%(AdditionalLibraryDirectories)
[DEBUG PROPERTIES WINDOW]
Linker -> Input -> Additional Dependencies: sfml-system-d.lib;sfml-graphics-d.lib;sfml-audio-d.lib;sfml-window-d.lib;sfml-network-d.lib;sfml-main-d.lib;%(AdditionalDependencies)
[RELEASE PROPERTIES WINDOW]
Linker -> Input -> Additional Dependencies: sfml-system.lib;sfml-graphics.lib;sfml-audio.lib;sfml-window.lib;sfml-network.lib;sfml-main-d.lib;%(AdditionalDependencies)

DLLs in <proj location>/x64/Debug/ : openal32.dll, sfml-audio-2.dll, sfml-audio-d-2.dll, sfml-graphics-2.dll, sfml-graphics-d-2.dll, sfml-network-2.dll, sfml-network-d-2.dll, sfml-system-2.dll, sfml-system-d-2.dll, sfml-window-2.dll, sfml-window-d-2.dll

This is quite interesting to me but I also am fairly devastated having been working on this project for weeks now and to have an error I cant resolve come out when I thought it could not.

Compile Output:
1>------ Build started: Project: ########, Configuration: Debug x64 ------
1>x64\Debug\######.obj : warning LNK4042: object specified more than once; extras ignored
1>main.obj : error LNK2019: unresolved external symbol "public: __cdecl ######::Ver######(class sf::CircleShape)" (??0######@@QEAA@VCircleShape@sf@@@Z) referenced in function main
1>main.obj : error LNK2019: unresolved external symbol "public: void __cdecl ######::#####(class sf::Vector2<float>)" (?######@######@@QEAAXV?$Vector2@M@sf@@@Z) referenced in function main
1>main.obj : error LNK2019: unresolved external symbol "public: void __cdecl ######::######(class sf::Vector2<float>)" (?#######@#######@@QEAAXV?$Vector2@M@sf@@@Z) referenced in function main
1>main.obj : error LNK2019: unresolved external symbol "public: class sf::Vector2<float> __cdecl #######::######(void)" (?######@######@@QEAA?AV?$Vector2@M@sf@@XZ) referenced in function main
1>main.obj : error LNK2019: unresolved external symbol "public: void __cdecl ######::#######(float)" (?######@#######@@QEAAXM@Z) referenced in function main
1>main.obj : error LNK2019: unresolved external symbol "public: void __cdecl #####::#####(class sf::Vector2<float>)" (?#####@#######@@QEAAXV?$Vector2@M@sf@@@Z) referenced in function main
1>Z:\Vtop\C++ Stuff\#####\x64\Debug\#######.exe : fatal error LNK1120: 6 unresolved externals
1>Done building project "########.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build started at 10:28 PM and took 00.328 seconds ==========



Thank You for reading! Apologies for bad English or translations.
« Last Edit: August 25, 2023, 05:55:14 am by Rowvan »

Rowvan

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Visual Studio Linker Errors (out of nowhere)
« Reply #1 on: August 25, 2023, 05:52:54 am »
Resolved! (for now, will update)

Solution is after the paragraph

After seeing that LNK4042 does not exist on Microsoft's own linker error page (see link #1 at bottom), I decided to investigate. Turns out, there are people with the same issue as me going as far back as 13 years ago! (see link #2 & #3) After my own solution (deleting the <filename>.obj file referenced by the LNK4042 error in the debug folder of my project) somewhat worked (i just kept deleting it  :P), I implemented the solution as follows:

SOLUTION:
Open the project properties and the change the value under
Code: [Select]
C++ -> Output Files -> Object File Name to be the following:
Code: [Select]
$(IntDir)/%(RelativeDir)/(taken from link #3)

(so far, works for me. again, will update)


1. https://learn.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-errors-and-warnings
2. https://stackoverflow.com/questions/3729515/visual-studio-2010-2008-cant-handle-source-files-with-identical-names-in-diff
3. https://stackoverflow.com/questions/3695174/visual-studio-2010s-strange-warning-lnk4042

 

anything