I have an issue with the new CMake Build Tool. It basically works, but there is a catch.
My CMakeLists.txt file of my SFML-Program looks as follows:
cmake_minimum_required(VERSION 3.10)
project(observer4)
set(CMAKE_CXX_STANDARD 17)
set(SFML_DIR "C:/SFML")
find_package(SFML COMPONENTS graphics window system)
add_executable(observer4 main.cpp )
target_link_libraries(observer4 sfml-graphics sfml-audio)
When run CMake everything works smoothly.
-- Found SFML 2.5.1 in C:/SFML
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Nextcloud/C++/observer4/cmake-build-debug
1. When I compile SFML Source-Code (v.2.5.1.) with CMAKE_BUILD_TYPE set to Debug and put everything to C:/SFML, and copy all newly created dll-files...
sfml-graphics-d-2.dll
sfml-audio-d-2.dll
sfml-network-d-2.dll
sfml-system-d-2.dll
sfml-window-d-2.dll
...to the cmake-build-debug-folder of my SFML-Program where the binary that is compiled in debug-mode will get created, everything works fine; the SFML-Application starts without hassle.
But when i now repeat compiling SFML with CMAKE_BUILD_TYPE set to Release, which adds the corresponding compiled "release-SFML-Files" to C:/SFML, the compilation of the SFML-Program in debug-mode suddenly breaks.
The compilation in debug-mode fails with:
Process finished with exit code -1073741515 (0xC0000135)
In the folder C:/SFML/libs this files resides:
libsfml-audio-d.a
libsfml-graphics-d.a
libsfml-main-d.a
libsfml-network-d.a
libsfml-system-d.a
libsfml-window-d.a
[all release and debug DLL-Files]
libsfml-audio.a
libsfml-graphics.a
libsfml-main.a
libsfml-network.a
libsfml-system.a
libsfml-window.a
I did not touch the debug-dll-files in the cmake-build-debug-folder of my SFML-Program where the binary is being compiled.
When i delete
libsfml-audio.a
libsfml-graphics.a
libsfml-main.a
libsfml-network.a
libsfml-system.a
libsfml-window.a
in C:/SFML/libs, which should be no problem, because i compile the SFML-Application in debug mode, the compiler throws this error:
mingw32-make.exe[2]: *** No rule to make target 'C:/SFML/lib/libsfml-graphics.a', needed by 'observer4.exe'. Stop.
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:75: CMakeFiles/observer4.dir/all] Error 2
mingw32-make.exe: *** [Makefile:83: all] Error 2
Why does the compiler need C:/SFML/lib/libsfml-graphics.a' ? Im compiling in debug-mode...he should rely on C:/SFML/lib/libsfml-graphics-d.a'. Same goes for the other files. when i return libsfml-graphics.a from trash, he asks for libsfml-window.a, when i return the file, he asks for libsfml-system.a etc. until it finally throws
Process finished with exit code -1073741515 (0xC0000135)
when all release-files (libsfml-audio.a, libsfml-graphics.a, etc. are back.
The weirdest thing is:
Process finished with exit code -1073741515 (0xC0000135)
goes away and the SFMl-Program starts when i copy the release-dll-files (sfml-graphics-2.dll, sfml-window-2.dll etc.) to the cmake-build-debug-folder. In fact, i can even delete all the debug-dll-files.
The Application only needs the release-files though i compiled it in debug-mode.
This is default behaviour out of the box which does not occure when i use a FindSFML.cmake file. When using FindSFML.cmake i can have all SFML-files (debug & release) in C:/SFML/libs in one place and just use the debug-dll-files for the debug build and the release-dll-files for my release-build.
Hi Laurent,
i was able to tackle the issue further down. It seems to be not related to the new SFML CMake System but to my IDE (Clion). Here are the exact steps that lead to the error i encountered. I noticed that when i compile everything "by hand" via CMD the error does not occure. However compiling with CLion provokes the error.
In Detail:
Steps:
1. Download SFML from Github
(https://live.staticflickr.com/65535/49565998378_2b407b68cf_c.jpg)
2. Extract ZIP-Contents to Download-Folder
(https://live.staticflickr.com/65535/49566732232_4c1ba73444_c.jpg)
3. Open Up CMake
- Set „Where is the source code“ to SFML-Directory in Download-Folder
- Set „Where to build the binaries“ to C:/SFML which will be the place to store all SFML libraries
(https://live.staticflickr.com/65535/49565998328_4fa5bf7393_b.jpg)
4. Click on „Configure“, specify the Generator to „MinGW Makefiles“ since i use mingw-w64-compiler, use checkbox „Use default native compilers“, click „Ok“
(https://live.staticflickr.com/65535/49565998273_81b7002a1d.jpg)
5. Set „CMAKE_BUILD_TYPE“ to „Release“
and click on „Generate“
(https://live.staticflickr.com/65535/49566732147_8dd8ff036c_o.png)
6. Open CMD in administrator-mode, go to C:/SFML, compile the generated CMake-Makefile with command „mingw32-make“
(https://live.staticflickr.com/65535/49566499946_7f92418860_b.jpg)
7. I receive this compiled Libraries in C:/SFML/libs
(https://live.staticflickr.com/65535/49565998213_7ac108f7e4_o.png)
8. I copy the received dll-files (for example „sfml-graphics-2.dll“) from C:/SFML/libs to the Destination-Folder where the release-version of my SFML-Application is going to be compiled. Here it is „D:\Nextcloud\C++\observer4\cmake-build-release“
(https://live.staticflickr.com/65535/49566499896_bab4e1480d_b.jpg)
9. I open up CMD, go to that folder where the release version of my SFML-Application is going to be created and create a makefile with the command „cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release ..“
(https://live.staticflickr.com/65535/49566499826_6fe84db593_b.jpg)
10. Then i compile the project with „mingw32-make“ and run the executable. It starts without issues.
(https://live.staticflickr.com/65535/49565998073_6a81d26925_o.png)
11. I go back to CMake and repeat step 5. But this time i set CMAKE_BUILD_TYPE to „Debug“ and click on generate
(https://live.staticflickr.com/65535/49566731992_cbd2f32dd3_o.png)
12. I repeat Step 6, after compilation i have not only the release-libraries, but also the debug-libararies of SFML in „C:/SFML/libs“
(https://live.staticflickr.com/65535/49566499781_f8dd80e58c_o.png)
13. I copy the received dll-files (for example „sfml-graphics-d-2.dll) from C:/SFML/libs to the Destination-Folder where the debug version of my SFML-Application is going to be compiled. Here it is „D:\Nextcloud\C++\observer4\cmake-build-release“
14. Then i create a makefile with the command „cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug ..“ and compile.
The Program runs fine.
(https://live.staticflickr.com/65535/49566731977_ce451ef40e_o.png)
15. When i open my IDE Clion and run the program in release mode, it suddenly does not work anymore. The same applies when i try to start the release-version from CMD after i have tried to run it from Clion.
(https://live.staticflickr.com/65535/49566499706_c8ed0ef983_o.png)
16. Now when i switch the content of the CMakeLists.txt file in "„D:\Nextcloud\C++\observer4\" from
cmake_minimum_required(VERSION 3.10)
project(observer4)
set(CMAKE_CXX_STANDARD 17)
set(SFML_DIR "C:/SFML")
find_package(SFML COMPONENTS graphics window system)
add_executable(observer4 main.cpp etc. etc.)
target_link_libraries(observer4 sfml-graphics)
to
cmake_minimum_required(VERSION 3.10)
project(observer4)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/modules)
set(SFML_ROOT "C:/SFML")
find_package(SFML COMPONENTS graphics window system)
include_directories(${SFML_INCLUDE_DIR})
add_executable(observer4 main.cpp etc. etc.)
target_link_libraries(observer4 ${SFML_LIBRARIES})
and compile everything again, the SFML-Application starts running from Clion and CMD.