Skip to content

MinGW Multiple Definition Linker Errors When Attempting to Call Any raymath.h-based Function #171

@CasualYT31

Description

@CasualYT31

Hello, I am currently working on a project using raylib and raylib-cpp, with a friend. My code compiled and ran perfectly fine on my system (using MSVC build tools), but my friend has not been able to compile and link the code on his system (using MinGW build tools—specifically gcc version 10.3.0 (Rev5, Built by MSYS2 project)). We were able to replicate the issue using this code and these CMake settings:

// main.cpp : Defines the entry point for the application.

// NOTE: including "raymath.h" instead works
#include "raylib-cpp.hpp"

int main() {
	const float one = Lerp(0.0f, 2.0f, 0.5f);

	return 0;
}
# minimum version required is 3.14 because of FetchContent_MakeAvailable
cmake_minimum_required (VERSION 3.14)

project ("Error")

include(FetchContent)
# RayLib
FetchContent_Declare(raylib
	# specify the commit you depend on and update it regularly.
	GIT_REPOSITORY https://github.com/raysan5/raylib.git
	GIT_TAG 4.0.0
)
# Setting parameters for raylib
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples
set(BUILD_GAMES    OFF CACHE BOOL "" FORCE) # or games
FetchContent_MakeAvailable(raylib)

# RayLib C++ wrapper
FetchContent_Declare(raylib_cpp
	# specify the commit you depend on and update it regularly.
	GIT_REPOSITORY https://github.com/RobLoach/raylib-cpp.git
	GIT_TAG v4.1.0
)
FetchContent_MakeAvailable(raylib_cpp)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# Add source to this project's executable.
add_executable(${PROJECT_NAME} "main.cpp" )
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17)
target_link_libraries(${PROJECT_NAME} raylib raylib_cpp)

The issue seems to be that we cannot call raymath-based functions when using raylib-cpp. Whenever we do, this linker error pops up (it says GOGATClient here because that's the name of our project):

[main] Building folder: GOGATClient GOGATClient
[build] Starting build
[proc] Executing command: D:/CMake/bin/cmake.exe --build c:/Users/User/Desktop/code/c++/GOGATClient/build --config Debug --target GOGATClient -j 10 --
[build] Consolidate compiler generated dependencies of target glfw
[build] [ 61%] Built target glfw
[build] Consolidate compiler generated dependencies of target raylib
[build] [ 92%] Built target raylib
[build] Consolidate compiler generated dependencies of target GOGATClient
[build] [ 96%] Building CXX object CMakeFiles/GOGATClient.dir/main.cpp.obj
[build] [100%] Linking CXX executable bin/GOGATClient.exe
[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: _deps/raylib-build/raylib/libraylib.a(rcore.c.obj): in function `Lerp':
[build] C:/Users/User/Desktop/code/c++/GOGATClient/build/_deps/raylib-src/src/raymath.h:175: multiple definition of `Lerp'; CMakeFiles/GOGATClient.dir/objects.a(main.cpp.obj):C:/Users/User/Desktop/code/c++/GOGATClient/build/_deps/raylib-src/src/raymath.h:175: first defined here
[build] collect2.exe: error: ld returned 1 exit status
[build] make[3]: *** [CMakeFiles/GOGATClient.dir/build.make:103: bin/GOGATClient.exe] Error 1
[build] make[2]: *** [CMakeFiles/Makefile2:181: CMakeFiles/GOGATClient.dir/all] Error 2
[build] make[1]: *** [CMakeFiles/Makefile2:188: CMakeFiles/GOGATClient.dir/rule] Error 2
[build] make: *** [Makefile:189: GOGATClient] Error 2
[build] Build finished with exit code 2

The only explanation I can come up with is that raylib-cpp somehow includes raymath.h twice. Including raymath.h across multiple files in the project does not cause any issues.

Could this really be an issue with raylib-cpp? Or is this an issue with the way we are trying to use the library? Thanks for your time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions