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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - LazyMechanic

Pages: [1]
1
General / Re: Linking trouble VS 2019 + Clang
« on: July 02, 2019, 06:01:29 pm »
Your CMake library definition order is wrong.
It should always follow the "X depends on Y, so X has to come before Y"-rule.

sfml-system, sfml-window, sfml-graphics, sfml-audio, sfml-network

With SFML 2.5 you can also just specify sfml-graphics and the CMake config will automatically link against sfml-window and sfml-system.


I tried to use different order of dependencies but nothing happens. Why the project builds in the terminal but not in the VS (also with wrong order)?

2
General / Linking trouble VS 2019 + Clang
« on: July 02, 2019, 03:53:07 pm »
I want to link the library as shared (static linking has same trouble either).

I have:
  • Windows 10
  • Cmake 3.15
  • Visual studio 19 (or Clion)
  • Clang compiler (VS based, and from MSYS2 package)

What I do:
  • Download SFML 2.5.1 for MinGW 64bit
  • Unpack to D:/dev/SFML-2.5.1
  • Create minimal test main.cpp:
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}
 
  • Create CMakeLists.txt with following:
# ....
find_package(SFML 2.5 COMPONENTS system window network graphics audio REQUIRED)

if (NOT ${SFML_FOUND})
    message(FATAL_ERROR "SFML couldn't be located")
endif()

set(SFML_LIBRARIES
        sfml-graphics
        sfml-network
        sfml-window
        sfml-audio
        sfml-system)

# ...

add_executable(TrueEngine
        ${TRUEENGINE_CORE_SRCS})

target_link_libraries(TrueEngine
        ${SFML_LIBRARIES}
        ${LUA_LIBRARIES})
# ....
# P.S. find_package(...) found them
  • Generate Visual Studio CMake project with following settings(1. VS clang, 2. Clang from MSYS2):
       
{
    "name": "x64-Clang-Debug",
    "generator": "Ninja",
    "configurationType": "Debug",
    "buildRoot": "${projectDir}\\out\\build\\${name}",
    "installRoot": "${projectDir}\\out\\install\\${name}",
    "cmakeCommandArgs": "-DSFML_DIR=\"D:/dev/SFML-2.5.1/lib/cmake/SFML\" -DLUA_LIBRARY=\"D:/dev/lua/liblua53.a\" -DLUA_INCLUDE_DIR=\"D:/dev/lua/include\"",
    "buildCommandArgs": "-v",
    "ctestCommandArgs": "",
    "inheritEnvironments": [ "clang_cl_x64" ],
    "variables": []
},
{
    "name": "x64-Clang-Debug-8.X.X",
    "generator": "Ninja",
    "configurationType": "Debug",
    "buildRoot": "${projectDir}\\out\\build\\${name}",
    "installRoot": "${projectDir}\\out\\install\\${name}",
    "cmakeCommandArgs": "-DSFML_DIR=\"D:/dev/SFML-2.5.1/lib/cmake/SFML\" -DLUA_LIBRARY=\"D:/dev/lua/liblua53.a\" -DLUA_INCLUDE_DIR=\"D:/dev/lua/include\"",
    "buildCommandArgs": "-v",
    "ctestCommandArgs": "",
    "inheritEnvironments": [ "clang_cl_x64" ],
    "variables": [
        {
            "name": "CMAKE_C_COMPILER",
            "value": "C:/msys64/mingw64/bin/clang-cl.exe",
            "type": "FILEPATH"
        },
        {
            "name": "CMAKE_CXX_COMPILER",
            "value": "C:/msys64/mingw64/bin/clang-cl.exe",
            "type": "FILEPATH"
        }
    ]
}
 
  • Generate cmake cashe and build

After I have this errors from both compiler:

Quote
>------ Build All started: Project: embercore-client, Configuration: x64-Clang-Debug ------
  [1/1] cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=src\TE\CMakeFiles\TrueEngine.dir --rc=C:\WINDOW~1\10\bin\100177~1.0\x64\rc.exe --mt=C:\WINDOW~1\10\bin\100177~1.0\x64\mt.exe --manifests  -- C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1421~1.277\bin\Hostx64\x64\link.exe /nologo src\TE\CMakeFiles\TrueEngine.dir\Core\main.cpp.obj src\TE\CMakeFiles\TrueEngine.dir\Core\TrueEngine.cpp.obj src\TE\CMakeFiles\TrueEngine.dir\Core\AppTraits.cpp.obj src\TE\CMakeFiles\TrueEngine.dir\Core\VideoSettings.cpp.obj src\TE\CMakeFiles\TrueEngine.dir\Core\Application.cpp.obj src\TE\CMakeFiles\TrueEngine.dir\Core\Input.cpp.obj src\TE\CMakeFiles\TrueEngine.dir\Core\EventHandler.cpp.obj  /out:..\..\..\bin\TrueEngine.exe /implib:src\TE\TrueEngine.lib /pdb:..\..\..\bin\TrueEngine.pdb /version:0.0  /machine:x64 /debug /INCREMENTAL /subsystem:console  D:\dev\SFML-2.5.1\lib\libsfml-graphics-d.a D:\dev\SFML-2.5.1\lib\libsfml-network-d.a D:\dev\SFML-2.5.1\lib\libsfml-window-d.a D:\dev\SFML-2.5.1\lib\libsfml-audio-d.a D:\dev\SFML-2.5.1\lib\libsfml-system-d.a D:\dev\lua\liblua53.a kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
  FAILED: ../../../bin/TrueEngine.exe
  cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=src\TE\CMakeFiles\TrueEngine.dir --rc=C:\WINDOW~1\10\bin\100177~1.0\x64\rc.exe --mt=C:\WINDOW~1\10\bin\100177~1.0\x64\mt.exe --manifests  -- C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1421~1.277\bin\Hostx64\x64\link.exe /nologo src\TE\CMakeFiles\TrueEngine.dir\Core\main.cpp.obj src\TE\CMakeFiles\TrueEngine.dir\Core\TrueEngine.cpp.obj src\TE\CMakeFiles\TrueEngine.dir\Core\AppTraits.cpp.obj src\TE\CMakeFiles\TrueEngine.dir\Core\VideoSettings.cpp.obj src\TE\CMakeFiles\TrueEngine.dir\Core\Application.cpp.obj src\TE\CMakeFiles\TrueEngine.dir\Core\Input.cpp.obj src\TE\CMakeFiles\TrueEngine.dir\Core\EventHandler.cpp.obj  /out:..\..\..\bin\TrueEngine.exe /implib:src\TE\TrueEngine.lib /pdb:..\..\..\bin\TrueEngine.pdb /version:0.0  /machine:x64 /debug /INCREMENTAL /subsystem:console  D:\dev\SFML-2.5.1\lib\libsfml-graphics-d.a D:\dev\SFML-2.5.1\lib\libsfml-network-d.a D:\dev\SFML-2.5.1\lib\libsfml-window-d.a D:\dev\SFML-2.5.1\lib\libsfml-audio-d.a D:\dev\SFML-2.5.1\lib\libsfml-system-d.a D:\dev\lua\liblua53.a kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
  LINK Pass 1: command "C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1421~1.277\bin\Hostx64\x64\link.exe /nologo src\TE\CMakeFiles\TrueEngine.dir\Core\main.cpp.obj src\TE\CMakeFiles\TrueEngine.dir\Core\TrueEngine.cpp.obj src\TE\CMakeFiles\TrueEngine.dir\Core\AppTraits.cpp.obj src\TE\CMakeFiles\TrueEngine.dir\Core\VideoSettings.cpp.obj src\TE\CMakeFiles\TrueEngine.dir\Core\Application.cpp.obj src\TE\CMakeFiles\TrueEngine.dir\Core\Input.cpp.obj src\TE\CMakeFiles\TrueEngine.dir\Core\EventHandler.cpp.obj /out:..\..\..\bin\TrueEngine.exe /implib:src\TE\TrueEngine.lib /pdb:..\..\..\bin\TrueEngine.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console D:\dev\SFML-2.5.1\lib\libsfml-graphics-d.a D:\dev\SFML-2.5.1\lib\libsfml-network-d.a D:\dev\SFML-2.5.1\lib\libsfml-window-d.a D:\dev\SFML-2.5.1\lib\libsfml-audio-d.a D:\dev\SFML-2.5.1\lib\libsfml-system-d.a D:\dev\lua\liblua53.a kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:src\TE\CMakeFiles\TrueEngine.dir/intermediate.manifest src\TE\CMakeFiles\TrueEngine.dir/manifest.res" failed (exit code 1120) with the following output:
D:\Projects\main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::String::String(char const *,class std::locale const &)" (__imp_??0String@sf@@QEAA@PEBDAEBVlocale@std@@@Z) referenced in function main
D:\Projects\AppTraits.cpp.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::String::String(char const *,class std::locale const &)" (__imp_??0String@sf@@QEAA@PEBDAEBVlocale@std@@@Z)
D:\Projects\main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (__imp_??0VideoMode@sf@@QEAA@III@Z) referenced in function main
D:\Projects\main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::RenderWindow::RenderWindow(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (__imp_??0RenderWindow@sf@@QEAA@VVideoMode@1@AEBVString@1@IAEBUContextSettings@1@@Z) referenced in function main
D:\Projects\main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::String::~String(void)" (__imp_??1String@sf@@QEAA@XZ) referenced in function main
D:\Projects\main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::CircleShape::CircleShape(float,unsigned __int64)" (__imp_??0CircleShape@sf@@QEAA@M_K@Z) referenced in function main
D:\Projects\main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class sf::Color const sf::Color::Green" (__imp_?Green@Color@sf@@2V12@B) referenced in function main
D:\Projects\main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl sf::Shape::setFillColor(class sf::Color const &)" (__imp_?setFillColor@Shape@sf@@QEAAXAEBVColor@2@@Z) referenced in function main
D:\Projects\main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __cdecl sf::Window::isOpen(void)const " (__imp_?isOpen@Window@sf@@QEBA_NXZ) referenced in function main
D:\Projects\main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __cdecl sf::Window::pollEvent(class sf::Event &)" (__imp_?pollEvent@Window@sf@@QEAA_NAEAVEvent@2@@Z) referenced in function main
D:\Projects\main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl sf::Window::close(void)" (__imp_?close@Window@sf@@QEAAXXZ) referenced in function main
D:\Projects\main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (__imp_??0Color@sf@@QEAA@EEEE@Z) referenced in function main
D:\Projects\main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl sf::RenderTarget::clear(class sf::Color const &)" (__imp_?clear@RenderTarget@sf@@QEAAXAEBVColor@2@@Z) referenced in function main
D:\Projects\main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class sf::RenderStates const sf::RenderStates::Default" (__imp_?Default@RenderStates@sf@@2V12@B) referenced in function main
D:\Projects\main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl sf::RenderTarget::draw(class sf::Drawable const &,class sf::RenderStates const &)" (__imp_?draw@RenderTarget@sf@@QEAAXAEBVDrawable@2@AEBVRenderStates@2@@Z) referenced in function main
D:\Projects\main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl sf::Window::display(void)" (__imp_?display@Window@sf@@QEAAXXZ) referenced in function main
D:\Projects\main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl sf::CircleShape::~CircleShape(void)" (__imp_??1CircleShape@sf@@UEAA@XZ) referenced in function main
D:\Projects\main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl sf::RenderWindow::~RenderWindow(void)" (__imp_??1RenderWindow@sf@@UEAA@XZ) referenced in function main
D:\Projects\TrueEngine.cpp.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl sf::RenderWindow::~RenderWindow(void)" (__imp_??1RenderWindow@sf@@UEAA@XZ)
D:\Projects\Application.cpp.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl sf::RenderWindow::~RenderWindow(void)" (__imp_??1RenderWindow@sf@@UEAA@XZ)
D:\Projects\AppTraits.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::String::String(class sf::String const &)" (__imp_??0String@sf@@QEAA@AEBV01@@Z) referenced in function "public: __cdecl te::AppTraits::AppTraits(class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (??0AppTraits@te@@QEAA@AEBVString@sf@@IAEBUContextSettings@3@@Z)
D:\Projects\VideoSettings.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::VideoMode::VideoMode(void)" (__imp_??0VideoMode@sf@@QEAA@XZ) referenced in function "public: __cdecl te::VideoSettings::VideoSettings(void)" (??0VideoSettings@te@@QEAA@XZ)
D:\Projects\Application.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::RenderWindow::RenderWindow(void)" (__imp_??0RenderWindow@sf@@QEAA@XZ) referenced in function "public: __cdecl te::Application::Application(class te::AppTraits const &,class te::VideoSettings const &)" (??0Application@te@@QEAA@AEBVAppTraits@1@AEBVVideoSettings@1@@Z)
D:\Projects\Application.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl sf::Window::create(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (__imp_?create@Window@sf@@QEAAXVVideoMode@2@AEBVString@2@IAEBUContextSettings@2@@Z) referenced in function "public: __cdecl te::Application::Application(class te::AppTraits const &,class te::VideoSettings const &)" (??0Application@te@@QEAA@AEBVAppTraits@1@AEBVVideoSettings@1@@Z)
D:\bin\TrueEngine.exe : fatal error LNK1120: 21 unresolved externals
  ninja: build stopped: subcommand failed.

Build All failed.

I see that libraries are not linked to the project, but I dont know why.

If I try to compile from a terminal, then all is fine, for example:
$ cmake .. -G "MinGW Makefiles" -DCMAKE_SH="CMAKE_SH-NOTFOUND" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DSFML_DIR="D:/dev/SFML-2.5.1/lib/cmake/SFML" -DLUA_LIBRARY="D:/dev/lua/liblua53.a" -DLUA_INCLUDE_DIR="D:/dev/lua/include" -DCMAKE_BUILD_TYPE=debug
-- Found SFML 2.5.1 in D:/dev/SFML-2.5.1/lib/cmake/SFML
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Projects/embercore-client/testbuild

 $ cmake --build .
Scanning dependencies of target TrueEngine
[ 12%] Building CXX object src/TE/CMakeFiles/TrueEngine.dir/Core/main.cpp.obj
[ 25%] Building CXX object src/TE/CMakeFiles/TrueEngine.dir/Core/TrueEngine.cpp.obj
[ 37%] Building CXX object src/TE/CMakeFiles/TrueEngine.dir/Core/AppTraits.cpp.obj
[ 50%] Building CXX object src/TE/CMakeFiles/TrueEngine.dir/Core/VideoSettings.cpp.obj
[ 62%] Building CXX object src/TE/CMakeFiles/TrueEngine.dir/Core/Application.cpp.obj
[ 75%] Building CXX object src/TE/CMakeFiles/TrueEngine.dir/Core/Input.cpp.obj
D:\Projects\embercore-client\src\TE\Core\Input.cpp:17:12: warning: 19 enumeration values not handled in switch: 'Closed', 'Resized', 'LostFocus'... [-Wswitch]
    switch(inputEvent.type) {
           ^
1 warning generated.
[ 87%] Building CXX object src/TE/CMakeFiles/TrueEngine.dir/Core/EventHandler.cpp.obj
[100%] Linking CXX executable ..\..\..\bin\TrueEngine.exe
[100%] Built target TrueEngine
 

And it works.

What I do wrong in VS?

Pages: [1]