SDL found with PkgConfig and MSVC (does not compile) - c++

I am trying to set up a cross platform project.
In Windows I have installed package SDL2 with MSYS2 for x86 and x64.
In my CMakeLists.txt I have:
find_package(PkgConfig REQUIRED)
pkg_search_module(SDL2
REQUIRED sdl2 sdl
IMPORTED_TARGET)
if(TARGET PkgConfig::SDL2)
message(STATUS "Found SDL2")
endif()
Package seems to be found both for MinGW and MSVC.
Simple program compiles with MinGW
#include <SDL/SDL.h>
#undef main
int main()
{
return 0;
}
However with MSVC SDL header can't be found and the program does not compile.
C:\dev\repos\UWCASdk\Sandbox\JoySDL\joyTest.cpp(2): fatal error C1083: Cannot open include file: 'SDL/SDL.h': No such file or directory
NMAKE : fatal error U1077: 'C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1426~1.288\bin\Hostx86\x64\cl.exe' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\bin\HostX86\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\bin\HostX86\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\bin\HostX86\x64\nmake.exe"' : return code '0x2'
Stop.
Is it not possible to use PkgConfig with MSVC? Or should I use another package manager?

Related

How do I fix a linker error in Clion when there seems to be no problem with the code?

So, I have no code, just empty files and a CMake, but I keep getting that Linker Error. Can someone please explain in a lot of detail what my problem is? Some info I have is that I am supposed to be using Visual Studio 2015 as my compiler and stuff, which I think I already have set up.
The Error:
[100%] Linking CXX executable Debug\CinderGame\CinderGame.exe
NMAKE : fatal error U1077: '"C:\Program Files\JetBrains\CLion 2020.2.3\bin\cmake\win\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\nmake.exe"' : return code '0x2'
Stop.
LINK Pass 1: command "C:\PROGRA~2\MICROS~1.0\VC\bin\link.exe /nologo #CMakeFiles\CinderGame.dir\objects1.rsp /out:Debug\CinderGame\CinderGame.exe /implib:CinderGame.lib /pdb:C:\Users\cesar\Documents\GitHub\final-project-cesarmonsalud\cmake-build-debug\Debug\CinderGame\CinderGame.pdb /version:0.0 /machine:X86 /debug /INCREMENTAL /subsystem:windows /NODEFAULTLIB:LIBCMT /NODEFAULTLIB:LIBCPMT -LIBPATH:C:\Users\cesar\Desktop\cinder_0.9.2_vc2015\lib\msw\x86 C:\Users\cesar\Desktop\cinder_0.9.2_vc2015\lib\msw\x86\Debug\v140\cinder.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\CinderGame.dir/intermediate.manifest CMakeFiles\CinderGame.dir/manifest.res" failed (exit code 1120) with the following output:
LIBCMTD.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol _WinMain#16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main##YAHXZ)
Debug\CinderGame\CinderGame.exe : fatal error LNK1120: 1 unresolved externals
The Code:
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 11)
project(Connect4)
# This tells the compiler to not aggressively optimize and
# to include debugging information so that the debugger
# can properly read what's going on.
set(CMAKE_BUILD_TYPE Debug)
# Let's ensure -std=c++xx instead of -std=g++xx
set(CMAKE_CXX_EXTENSIONS OFF)
# Let's nicely support folders in IDE's
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Warning flags
if(MSVC)
# warning level 3 and all warnings as errors
add_compile_options(/W3)
else()
# lots of warnings and all warnings as errors
add_compile_options(-Wall -Wpedantic -Werror)
endif()
# FetchContent added in CMake 3.11, downloads during the configure step
include(FetchContent)
# FetchContent_MakeAvailable was not added until CMake 3.14
if(${CMAKE_VERSION} VERSION_LESS 3.14)
include(cmake/add_FetchContent_MakeAvailable.cmake)
endif()
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG devel
)
# Adds Catch2 testing library
FetchContent_GetProperties(catch2)
if(NOT catch2_POPULATED)
FetchContent_Populate(catch2)
add_library(catch2 INTERFACE )
target_include_directories(catch2 INTERFACE ${catch2_SOURCE_DIR}/single_include)
endif()
get_filename_component(CINDER_PATH "C:/Users/cesar/Desktop/cinder_0.9.2_vc2015" ABSOLUTE)
get_filename_component(APP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/" ABSOLUTE)
include("${CINDER_PATH}/proj/cmake/modules/cinderMakeApp.cmake")
list(APPEND CORE_SOURCE_FILES
)
list(APPEND SOURCE_FILES ${CORE_SOURCE_FILES}
include/core/Connect4.h
include/visualizer/FinalProjectApp.h
src/core/Connect4.cpp
src/visualizer/FinalProjectApp.cpp
)
list(APPEND TEST_FILES tests/Connect4Tests.cpp)
ci_make_app(
APP_NAME CinderGame
CINDER_PATH ${CINDER_PATH}
SOURCES apps/cinder_game.cpp ${SOURCE_FILES}
INCLUDES include
)
ci_make_app(
APP_NAME ConsoleGame
CINDER_PATH ${CINDER_PATH}
SOURCES apps/main_console_game.cpp ${SOURCE_FILES}
INCLUDES include
)
ci_make_app(
APP_NAME GameTest
CINDER_PATH ${CINDER_PATH}
SOURCES tests/Connect4Tests.cpp ${SOURCE_FILES} ${TEST_FILES}
INCLUDES include
LIBRARIES catch2
)
if(MSVC)
set_property(TARGET GameTest APPEND_STRING PROPERTY LINK_FLAGS " /SUBSYSTEM:CONSOLE")
endif()
The culprit is probably:
if(MSVC)
set_property(TARGET GameTest APPEND_STRING PROPERTY LINK_FLAGS " /SUBSYSTEM:CONSOLE")
endif()
This tells the linker to build for a console subsystem, which does not have an implicit WinMain function: you'd have to write one yourself if you need a console build.
If you don't need a console build, you can change it to /SUBSYSTEM:WINDOWS and a WinMain will be supplied by MFC.

Cmake - fatal error U1073: don't know how to make

Here is my main CmakeLists.txt:
cmake_minimum_required(VERSION 3.16)
project(Vibranium_Core)
set(CMAKE_CXX_STANDARD 14)
find_package(Boost 1.72.0)
if(NOT Boost_FOUND)
message(FATAL_ERROR "Could not find boost!")
endif()
include_directories(${Boost_INCLUDE_DIR})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Source/Common)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Source/Core/WorldServer)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Source/Core/AuthServer)
set_target_properties(
Common WorldServer AuthServer
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
Here is my: /Source/Common/CmakeLists.txt:`
add_library(Common SHARED Config.cpp Config.h Logger.cpp Logger.h)
target_include_directories(Common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
When I try to build my project I get:
NMAKE : fatal error U1073: don't know how to make 'bin\lib\Common.lib'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
I have this problem only on Windows. When I try to build the project on Linux there is no issue. What is causing this problem and how can I fix it?

Cannot link to Boost library with MSVC: Cannot open file *.lib

I'm using CLion and CMake to link with Boost and as toolchain I chose the MSVC compiler:
My architecture is configured as amd64 since I'm running a 64-bit system (the default of x86 only tries to find the 32-bit versions of Boost which I don't want).
Furthermore I compiled the 64-bit libraries using this guide. I setup my CMake file respectively:
set(BOOST_ROOT "C:/local/boost_1_69_0_b1_rc3")
set(BOOST_LIBRARYDIR "C:/local/boost_1_69_0_b1_rc3/stage/x64/lib")
set(BOOST_INCLUDEDIR "C:/local/boost_1_69_0_b1_rc3/boost")
My main.cpp compiles just fine but I'm getting a linker error:
====================[ Build | BoostTesting | Debug ]============================
C:\Users\User\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\183.4284.104\bin\cmake\win\bin\cmake.exe --build D:\Cpp\BoostTesting\cmake-build-debug --target BoostTesting --
[ 50%] Linking CXX executable BoostTesting.exe
LINK Pass 1: command "C:\PROGRA~2\MICROS~3\2017\ENTERP~1\VC\Tools\MSVC\1415~1.267\bin\Hostx64\x64\link.exe /nologo #CMakeFiles\BoostTesting.dir\objects1.rsp /out:BoostTesting.exe /implib:BoostTesting.lib /pdb:D:\Cpp\BoostTesting\cmake-build-debug\BoostTesting.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console C:\local\boost_1_69_0_b1_rc3\stage\x64\lib\libboost_filesystem-vc141-mt-gd-x64-1_69.lib C:\local\boost_1_69_0_b1_rc3\stage\x64\lib\libboost_system-vc141-mt-x64-1_69.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\BoostTesting.dir/intermediate.manifest CMakeFiles\BoostTesting.dir/manifest.res" failed (exit code 1104) with the following output:
LINK : fatal error LNK1104: cannot open file 'libboost_iostreams-vc141-mt-gd-x64-1_69.lib'
NMAKE : fatal error U1077: 'C:\Users\User\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\183.4284.104\bin\cmake\win\bin\cmake.exe' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
When using x86_amd64 as architecture it also fails to link. The other architectures don't make sense for my PC:
Using the pre-compiled binaries from here also fails to link. How to fix this linking problem?
Just setting BOOST_ROOT in CMakeLists.txt
set(BOOST_ROOT "C:/local/boost_1_69_0_b1_rc3")
and using amd64 as the architecture surprisingly did the trick now. Using MSVC with CMake is better supported with Visual Studio (quite obviously) and linking to Boost was no issue anymore. Now the build also works from CLion but Visual Studio should be preferred until CLion maybe gets better MSVC integration.

CMake generated program fails to link on Windows: tries to link to non-existent file

I am trying to compile a very simple test program on Windows and keep getting linker errors. The program to link is the following:
#include <boost/asio/io_context.hpp>
int main()
{
boost::asio::io_context context;
}
While the CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(windows-test)
SET(CMAKE_CXX_STANDARD 17)
find_package(Boost 1.6.7 COMPONENTS system)
include_directories("${Boost_INCLUDE_DIRS}")
add_executable(windows-test main.cpp)
target_link_libraries(windows-test Boost::system)
When building this using nmake, it fails with the following output:
-- Boost version: 1.67.0
-- Found the following Boost libraries:
-- system
-- Configuring done
-- Generating done
-- Build files have been written to: Z:/windows-test/build
[ 50%] Linking CXX executable windows-test.exe
LINK Pass 1: command "C:\PROGRA~2\MICROS~1\2017\BUILDT~1\VC\Tools\MSVC\1414~1.264\bin\Hostx64\x64\link.exe /nologo #CMakeFiles\windows-test.dir\objects1.rsp /out:windows-test.exe /implib:windows-test.lib /pdb:Z:\windows-test\build\windows-test.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console C:\local\boost_1_67_0\lib64-msvc-14.1\boost_system-vc141-mt-gd-x64-1_67.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\windows-test.dir/intermediate.manifest CMakeFiles\windows-test.dir/manifest.res" failed (exit code 1104) with the following output:
LINK : fatal error LNK1104: cannot open file 'libboost_system-vc141-mt-gd-x64-1_67.lib'
NMAKE : fatal error U1077: '"C:\Program Files\CMake\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.14.26428\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.14.26428\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
The file 'libboost_system-vc141-mt-gd-x64-1_67.lib' indeed does not exist on the system, but I don't know where it is coming from, since it does not appear on the linker command that it is executing. The linker command shows the file C:\local\boost_1_67_0\lib64-msvc-14.1\boost_system-vc141-mt-gd-x64-1_67.lib, which does exist.
Why oh why does it try to link to a missing file, that appears nowhere on the linker command? I feel way out of my depth here, since I haven't had to use Windows for almost 20 years and never before had to port to it.
Boost headers contain linker commands on Windows, so that Boost libraries are linked automatically when including the appropriate header. However, it seems your setup uses a different naming scheme for the libraries, which makes these fail to link.
You can disable the Boost auto-linking feature by defining the preprocessor macro BOOST_ALL_NO_LIB. Like this:
target_compile_definitions(windows-test PRIVATE BOOST_ALL_NO_LIB)

Setting up FLTK on windows with CMake

I'm trying to setup FLTK to build on windows with CMake with the Windows SDK.
So far here's what I've accomplished so far:
> svn co http://svn.easysw.com/public/fltk/fltk/branches/branch-1.3/ fltk-1.3
> cmake CMakeLists.txt -DOPTION_BUILD_EXAMPLES=NO -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=C:\dev\fltk-1.3
> nmake
> nmake install
No errors so far.
Then I created a test.cpp file with a hello world example I got off the documentation.
Here's my CMakeLists.txt:
cmake_minimum_required(VERSION 2.6)
project(Test)
find_package(FLTK REQUIRED NO_MODULE)
include(${FLTK_USE_FILE})
add_executable(test WIN32 test.cpp)
target_link_libraries(test fltk)
When I run cmake CMakeLists.txt I get an error asking me to set FLTK_DIR, so here's what I've got so far:
> cmake CMakeLists.txt
(error about FLTK_DIR)
> cmake CMakeLists.txt -DFLTK_DIR=C:\dev\fltk-1.3\CMake
> nmake
The last nmake command gives me this output:
[100%] Building CXX object CMakeFiles/test.dir/Test.cpp.obj
Test.cpp
Linking CXX executable test.exe
LINK : fatal error LNK1104: cannot open file ';.obj'
LINK Pass 1 failed. with 2
NMAKE : fatal error U1077: 'C:\dev\cmake-2.8.7-win32-x86\bin\cmake.exe' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\nmake.exe"' : return code '0x2'
Stop.
I tried letting FLTK install itself to the default location, which didn't make any difference.
So, can anyone help me get this working?
After hours of working on this I finally figured it out.
I had to comment out these 3 lines in FLTKConfig.cmake
if(NOT " /STACK:10000000 /machine:X86 " STREQUAL "")
set(FLTK_EXE_LINKER_FLAGS " /STACK:10000000 /machine:X86 ")
endif(NOT " /STACK:10000000 /machine:X86 " STREQUAL "")
They were causing it to add an ';' character into the command line for link.exe,causing it to try to link with ;.obj.
I also had to rebuild FLTK, and change all occurences of "/MD" to "/MT" in CMakeCache.txt.
Site manager for FLTK here.
I don't have enough rep to add a comment to the OP.
The http://easysw.com/ url in the OP's message is no longer valid.
For up to date download for FLTK source code, please refer to http://fltk.org/
Just click on the "Download" link. There you will find up to date source code downloads for tar files and SVN access info.