Sample file in CMake template does not compile
Following the instructions, upon running the first cmake .. I get the following output:
> cmake ..
-- Populating raylib_cpp
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/evan/Projects/Bungeon/build/_deps/raylib_cpp-subbuild
[ 11%] Performing update step for 'raylib_cpp-populate'
[ 22%] No patch step for 'raylib_cpp-populate'
[ 33%] No configure step for 'raylib_cpp-populate'
[ 44%] No build step for 'raylib_cpp-populate'
[ 55%] No install step for 'raylib_cpp-populate'
[ 66%] No test step for 'raylib_cpp-populate'
[ 77%] Completed 'raylib_cpp-populate'
[100%] Built target raylib_cpp-populate
CMake Error at CMakeLists.txt:56 (target_link_libraries):
The keyword signature for target_link_libraries has already been used with
the target "raylib_cpp_example". All uses of target_link_libraries with a
target must be either all-keyword or all-plain.
The uses of the keyword signature are here:
* CMakeLists.txt:46 (target_link_libraries)
This is after copying both the CMakeLists.txt and main.cpp files from the starter project, creating, and cd'ing into the build folder.
Working from the command line on macOS Monterey.
It's also worth noting that if I clone the repo, I'm able to run cmake .. fine, but running make after that yields this result:
[ 44%] Building CXX object examples/CMakeFiles/physics_demo.dir/physics/physics_demo.cpp.o
In file included from /Users/evan/Projects/raylib-cpp/examples/physics/physics_demo.cpp:22:
In file included from /Users/evan/Projects/raylib-cpp/include/Physics.hpp:5:
/Users/evan/Projects/raylib-cpp/include/./physac.hpp:10:10: fatal error: 'extras/physac.h' file not found
#include "extras/physac.h" // NOLINT
^~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [examples/CMakeFiles/physics_demo.dir/physics/physics_demo.cpp.o] Error 1
make[1]: *** [examples/CMakeFiles/physics_demo.dir/all] Error 2
make: *** [all] Error 2
#include "extras/physac.h" // NOLINT
Interesting... That's the same approach that the raylib demo takes. It should add the include directory with that extras directory there... :thinking:
CMake in the example
it's erroring out here...
# Checks if OSX and links appropriate frameworks (Only required on MacOS)
if (APPLE)
target_link_libraries(${PROJECT_NAME} "-framework IOKit")
target_link_libraries(${PROJECT_NAME} "-framework Cocoa")
target_link_libraries(${PROJECT_NAME} "-framework OpenGL")
endif()
Could you try this instead...
target_link_libraries(${PROJECT_NAME} "-framework IOKit -framework Cocoa -framework OpenGL")
Or even try removing that entirely?
Removing the if (APPLE) block in the CMakeLists seemed to have worked for me on Mac.
Thanks for the testing! Removed the block https://github.com/RobLoach/raylib-cpp/commit/e3bf04a36add426edf68b3b68a3ee59e77a62cc8
Hello @leftbones! I ran into the same issue with physac.h missing while trying to build the examples on my M1 Mac.
It looks like raysan5 forked Physac and updated it here (https://github.com/raysan5/physac), replacing the old #include "physac.h" with #include "extras/physac.h" in addition to removing Physac and its examples from raylib proper. That change was reflected here in raylib-cpp with this commit: https://github.com/RobLoach/raylib-cpp/commit/d0a04603dcfc08ed2e5a3f8b15d8c5bf1ae472e9#diff-f8b7d521f0390fa4a2c646e9e3e577d1ab82d6a78e9b4db4eb1e71ff26c9ac6d
In lieu of a proper solution, you can make a new extras folder in your local copy of https://github.com/RobLoach/raylib-cpp/tree/master/include and copy https://github.com/raysan5/physac/blob/master/src/physac.h into it. I guess it should work as long as extras/physac.h is somewhere on the include path, e.g., usr/local/include/extras/physac.h?
Once I did that, make built the examples, and the physics_demo executable ran fine.
I am sure there is a better place to put that header file or a nicer way to do this that does not involve directly modifying a local copy of raylib or raylib-cpp. I'm a little rusty on C++ and not very familiar with CMake, though.
RE the CMake error, I can confirm that @RobLoach 's fix above for the CMake file worked for me.
Thanks so much for the testing! I removed physac stuff from raylib-cpp since it was problematic, and made a follow up issue if people still want C++ implementations of that API https://github.com/RobLoach/raylib-cpp/issues/208