Setting up FLTK on windows with CMake - c++

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.

Related

libpng with directory tree zlib build error

I have the following cmake file:
cmake_minimum_required(VERSION 3.15)
add_subdirectory(googletest)
add_subdirectory(zlib)
# libpng setup
option(PNG_TESTS OFF)
set(PNG_TESTS OFF)
option(PNG_SHARED OFF)
set(PNG_SHARED OFF)
option(PNG_EXECUTABLES OFF)
set(PNG_EXECUTABLES OFF)
option(PNG_BUILD_ZLIB ON)
set(PNG_BUILD_ZLIB ON)
set(ZLIB_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/zlib" "${CMAKE_CURRENT_BINARY_DIR}/zlib")
set(ZLIB_LIBRARY "zlib")
add_subdirectory(libpng)
This generates the project correctly and zlib/googletest build is OK. pnglib on the other hand doesn't build:
1>Generating pnglibconf.out
1>Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29337 for x64
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>
1>pnglibconf.c
1>build/thirdparty/libpng/pnglibconf.c(34): fatal error C1083: Cannot open include file: 'zlib.h': No such file or directory
1>CMake Error at scripts/genout.cmake:78 (message):
1> Failed to generate build/thirdparty/libpng/pnglibconf.out.tf1
1>
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(238,5): error MSB8066: Custom build for 'build\CMakeFiles\4c907688e112b5b30b06f56662306981\pnglibconf.out.rule;build\CMakeFiles\4c907688e112b5b30b06f56662306981\pnglibconf.h.rule;build\CMakeFiles\5a2501006db4b4e75991d2f2c16bfadf\sym.out.rule;build\CMakeFiles\4c907688e112b5b30b06f56662306981\libpng.sym.rule;build\CMakeFiles\5a2501006db4b4e75991d2f2c16bfadf\vers.out.rule;build\CMakeFiles\4c907688e112b5b30b06f56662306981\libpng.vers.rule;build\CMakeFiles\5a2501006db4b4e75991d2f2c16bfadf\intprefix.out.rule;build\CMakeFiles\5a2501006db4b4e75991d2f2c16bfadf\prefix.out.rule;build\CMakeFiles\5a2501006db4b4e75991d2f2c16bfadf\symbols.chk.rule;build\CMakeFiles\e5199c38ed750451ee22eda432b56e2c\genfiles.rule' exited with code 1.
1>Done building project "genfiles.vcxproj" -- FAILED.
If I manually copy ${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt to ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h as genfiles target should do pnglib_static compiles fine.
...
if(NOT AWK OR ANDROID OR IOS)
# No awk available to generate sources; use pre-built pnglibconf.h
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt
${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h)
add_custom_target(genfiles) # Dummy
else()
...
Any idea on how to fix this? I would like to not alter the CMakeLists.txt from libpng to be easier to update to newer versions. I'm using the latest version from url = git://git.code.sf.net/p/libpng/code as documented on http://www.libpng.org/pub/png/libpng.html
After reading genout.cmake I've found this line:
set(AWK "C:/Program Files/Git/usr/bin/gawk.exe")
If I run CMake from cmd instead of git bash genout.cmake contains:
set(AWK "AWK-NOTFOUND")
Probably running CMake from git bash confuses the build system, but running CMake from cmd generates the project correctly.

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.

SDL found with PkgConfig and MSVC (does not compile)

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?

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)