Проблема компоновщика с vcpkg и CMake в windows -VSCode - PullRequest
0 голосов
/ 17 июня 2020

Я пытаюсь создать код на основе портов vcpkg в VSCode. (Я использую его с инструментами CMake и CMake для кода Visual Studio Code.) Но некоторые библиотеки не собираются, например sfml et c.

Мой исходный файл:

    #include <iostream>
    #include <SFML/Graphics.hpp>

    int main(int argc, char* argv[])
    {
        sf::Window m_w;
    }

У меня две очень похожие версии CMakeList.txt и, как и ожидалось, у меня две разные проблемы: первая версия CMakeList.txt

cmake_minimum_required(VERSION 3.18.0)
set(CMAKE_TOOLCHAIN_FILE "D:/repositories/VS/vcpkg-master/scripts/buildsystems/vcpkg.cmake")
include(CTest)
enable_testing()
find_package(SFML COMPONENTS system window graphics CONFIG REQUIRED)
add_executable(HelloWorld HelloWorld.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION CMAKE_PROJECT_VERSION)
include(CPack)
target_include_directories( HelloWorld PUBLIC ${CMAKE_BINARY_DIR})
target_link_libraries(HelloWorld PRIVATE FLAC OpenAL OpenGL Vorbis)
target_link_libraries(HelloWorld PRIVATE ${SFML_LIBRARIES})

и его вывод cmake

[main] Configuring folder: HelloWorld_cmake 
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Release "-DCMAKE_C_COMPILER:FILEPATH=C:\Program Files\LLVM\bin\clang-cl.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=C:\Program Files\LLVM\bin\clang-cl.exe" -Hd:/repositories/VS_Code/HelloWorld_cmake -Bd:/repositories/VS_Code/HelloWorld_cmake/build -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is Clang 10.0.0 with MSVC-like command-line
[cmake] -- The CXX compiler identification is Clang 10.0.0 with MSVC-like command-line
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/Program Files/LLVM/bin/clang-cl.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang-cl.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Found SFML 2.5.1 in D:/repositories/VS/vcpkg-master/installed/x64-windows/share/sfml
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: D:/repositories/VS_Code/HelloWorld_cmake/build
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[main] Building folder: HelloWorld_cmake HelloWorld
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build d:/repositories/VS_Code/HelloWorld_cmake/build --config Release --target HelloWorld -- -j 14
[build] [1/2  50% :: 0.235] Building CXX object CMakeFiles\HelloWorld.dir\HelloWorld.cpp.obj
[build] FAILED: CMakeFiles/HelloWorld.dir/HelloWorld.cpp.obj 
[build] C:\PROGRA~1\LLVM\bin\clang-cl.exe  /nologo -TP -DFLAC__NO_DLL -DOV_EXCLUDE_STATIC_CALLBACKS -I. /DWIN32 /D_WINDOWS /GR /EHsc /O2 /Ob2 /DNDEBUG -MD /showIncludes /FoCMakeFiles\HelloWorld.dir\HelloWorld.cpp.obj /FdCMakeFiles\HelloWorld.dir\ -c ..\HelloWorld.cpp
[build] ..\HelloWorld.cpp(4,10): fatal error: 'SFML/Graphics.hpp' file not found
[build] #include <SFML/Graphics.hpp>
[build]          ^~~~~~~~~~~~~~~~~~~
[build] 1 error generated.
[build] ninja: build stopped: subcommand failed.
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[build] Build finished with exit code 1

Второй:

cmake_minimum_required(VERSION 3.18.0)
set(CMAKE_TOOLCHAIN_FILE "D:/repositories/VS/vcpkg-master/scripts/buildsystems/vcpkg.cmake")
project(HelloWorld VERSION 0.0.0.0)
include(CTest)
enable_testing()
find_package(OpenAL CONFIG REQUIRED)
find_package(SFML COMPONENTS system window graphics CONFIG REQUIRED)
add_executable(HelloWorld HelloWorld.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION CMAKE_PROJECT_VERSION)
include(CPack)
target_include_directories( HelloWorld PUBLIC ${CMAKE_BINARY_DIR})
target_link_libraries(HelloWorld PRIVATE OpenAL::OpenAL)
target_link_libraries(HelloWorld PRIVATE FLAC OpenAL OpenGL Vorbis)
target_link_libraries(HelloWorld PRIVATE ${SFML_LIBRARIES})
[main] Configuring folder: HelloWorld_cmake 
[main] Configuring folder: HelloWorld_cmake 
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Release "-DCMAKE_C_COMPILER:FILEPATH=C:\Program Files\LLVM\bin\clang-cl.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=C:\Program Files\LLVM\bin\clang-cl.exe" -Hd:/repositories/VS_Code/HelloWorld_cmake -Bd:/repositories/VS_Code/HelloWorld_cmake/build -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Found SFML 2.5.1 in D:/repositories/VS/vcpkg-master/installed/x64-windows/share/sfml
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: D:/repositories/VS_Code/HelloWorld_cmake/build
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[main] Building folder: HelloWorld_cmake HelloWorld
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build d:/repositories/VS_Code/HelloWorld_cmake/build --config Release --target HelloWorld -- -j 14
[build] [1/2  50% :: 0.673] Building CXX object CMakeFiles\HelloWorld.dir\HelloWorld.cpp.obj
[build] [2/2 100% :: 0.711] Linking CXX executable HelloWorld.exe
[build] FAILED: HelloWorld.exe 
[build] cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\HelloWorld.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\mt.exe --manifests  -- C:\PROGRA~1\LLVM\bin\lld-link.exe /nologo CMakeFiles\HelloWorld.dir\HelloWorld.cpp.obj  /out:HelloWorld.exe /implib:HelloWorld.lib /pdb:HelloWorld.pdb /version:0.0 /machine:x64 /INCREMENTAL:NO /subsystem:console  D:\repositories\VS\vcpkg-master\installed\x64-windows\lib\OpenAL32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cmd.exe /C "cd /D D:\repositories\VS_Code\HelloWorld_cmake\build && powershell -noprofile -executionpolicy Bypass -file D:/repositories/VS/vcpkg-master/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary D:/repositories/VS_Code/HelloWorld_cmake/build/HelloWorld.exe -installedDir D:/repositories/VS/vcpkg-master/installed/x64-windows/bin -OutVariable out""
[build] LINK: command "C:\PROGRA~1\LLVM\bin\lld-link.exe /nologo CMakeFiles\HelloWorld.dir\HelloWorld.cpp.obj /out:HelloWorld.exe /implib:HelloWorld.lib /pdb:HelloWorld.pdb /version:0.0 /machine:x64 /INCREMENTAL:NO /subsystem:console D:\repositories\VS\vcpkg-master\installed\x64-windows\lib\OpenAL32.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:HelloWorld.exe.manifest" failed (exit code 1) with the following output:
[build] lld-link: error: undefined symbol: __declspec(dllimport) public: __cdecl sf::Window::Window(void)
[build] >>> referenced by CMakeFiles\HelloWorld.dir\HelloWorld.cpp.obj:(main)
[build] 
[build] lld-link: error: undefined symbol: __declspec(dllimport) public: virtual __cdecl sf::Window::~Window(void)
[build] >>> referenced by CMakeFiles\HelloWorld.dir\HelloWorld.cpp.obj:(main)
[build] ninja: build stopped: subcommand failed.
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[build] Build finished with exit code 1

В этой версии OpenAL представляет. При этом изменяется (например, glfw. Не имеет значения) ошибка в этой версии не меняется.

если я не использую sfml, однако, если я использую другой пакет, такой как SDL, никаких ошибок не возникает.

Например, Source:

#include "SDL2/SDL.h"
#include <stdio.h>

int main(int argc, char* argv[]) {

    SDL_Window *window;                    // Declare a pointer

    SDL_Init(SDL_INIT_VIDEO);              // Initialize SDL2

    // Create an application window with the following settings:
    window = SDL_CreateWindow(
        "An SDL2 window",                  // window title
        SDL_WINDOWPOS_UNDEFINED,           // initial x position
        SDL_WINDOWPOS_UNDEFINED,           // initial y position
        640,                               // width, in pixels
        480,                               // height, in pixels
        SDL_WINDOW_OPENGL                  // flags - see below
    );

    // Check that the window was successfully created
    if (window == NULL) {
        // In the case that the window could not be made...
        printf("Could not create window: %s\n", SDL_GetError());
        return 1;
    }

    // The window is open: could enter program loop here (see SDL_PollEvent())

    SDL_Delay(3000);  // Pause execution for 3000 milliseconds, for example

    // Close and destroy the window
    SDL_DestroyWindow(window);

    // Clean up
    SDL_Quit();
    return 0;
}

CMakeList - это

cmake_minimum_required(VERSION 3.18.0)
set(CMAKE_TOOLCHAIN_FILE "D:/repositories/VS/vcpkg-master/scripts/buildsystems/vcpkg.cmake")
project(HelloWorld VERSION 0.0.0.0)
include(CTest)
enable_testing()
find_package(SDL2 CONFIG REQUIRED)
add_executable(HelloWorld HelloWorld.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION CMAKE_PROJECT_VERSION)
include(CPack)
target_include_directories( HelloWorld PUBLIC ${CMAKE_BINARY_DIR})
target_link_libraries(HelloWorld PRIVATE SDL2::SDL2 SDL2::SDL2main)

Вывод CMake:

[main] Configuring folder: HelloWorld_cmake 
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Release "-DCMAKE_C_COMPILER:FILEPATH=C:\Program Files\LLVM\bin\clang-cl.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=C:\Program Files\LLVM\bin\clang-cl.exe" -Hd:/repositories/VS_Code/HelloWorld_cmake -Bd:/repositories/VS_Code/HelloWorld_cmake/build -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: D:/repositories/VS_Code/HelloWorld_cmake/build
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[main] Building folder: HelloWorld_cmake HelloWorld
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build d:/repositories/VS_Code/HelloWorld_cmake/build --config Release --target HelloWorld -- -j 14
[build] [1/2  50% :: 0.137] Building CXX object CMakeFiles\HelloWorld.dir\HelloWorld.cpp.obj
[build] [2/2 100% :: 0.606] Linking CXX executable HelloWorld.exe
[build] lld-link: warning: found both wmain and main; using latter
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[cmakefileapi-parser] Code model version (2.1) of cmake-file-api is unexpected. Expecting (2.0). IntelliSense configuration may be incorrect.
[build] Build finished with exit code 0

Ошибки нет. Это полностью работает.

Наконец, как я могу исправить эти проблемы? Почему возникают эти проблемы.

...