Issue
I've installed vcpkg and followed the install steps, the bootstrap and the integrate commands.
But I can't figure out why my C project wont link with raylib. I feel like I've followed all the steps and the project wont link, can anyone suggest a solution?
output from vcpkg list
:
glfw3:arm64-osx 3.3.9 GLFW is a free, Open Source, multi-platform libr...
raylib:arm64-osx 5.0 A simple and easy-to-use library to enjoy videog...
raylib[use-audio]:arm64-osx Build raylib with audio module
vcpkg-cmake-config:arm64-osx 2022-02-06#1
vcpkg-cmake:arm64-osx 2023-05-04
My cmake project with the toolchain set and linking to the MacOS deps as per instructions:
cmake_minimum_required(VERSION 3.24)
set(CMAKE_TOOLCHAIN_FILE "/Users/dev/vcpkg/scripts/buildsystems/vcpkg.cmake")
project(base VERSION 0.1.0 LANGUAGES C)
set(CMAKE_C_STANDARD 11)
message("[TOOLCHAIN] " ${CMAKE_TOOLCHAIN_FILE})
find_package(raylib CONFIG REQUIRED)
add_executable(base main.c)
if (APPLE)
target_link_libraries(base PRIVATE raylib "-framework IOKit" "-framework Cocoa" "-framework OpenGL")
else()
target_link_libraries(base PRIVATE raylib)
endif()
Example from raylib - basic window:
#include <stdlib.h>
#include "raylib.h"
int main(void)
{
///omitted.
}
Linker Error:
Omitted some of the output as it's too long:
[build] [2/2 100% :: 0.231] Linking C executable src/base
[build] FAILED: src/base
[build] : && /usr/bin/clang -g -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.0.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names src/CMakeFiles/base.dir/main.c.o -o src/base /Users/howardcolin/vcpkg/installed/arm64-osx/debug/lib/libraylib.a -framework IOKit -framework Cocoa -framework OpenGL -L/Users/howardcolin/vcpkg/installed/arm64-osx/debug/lib/pkgconfig/../../lib -lraylib -lglfw3 -framework Cocoa -framework IOKit -framework CoreFoundation && :
[build] ld: Undefined symbols:
[build] ___asan_handle_no_return, referenced from:
[build] _glfwExtensionSupported in libraylib.a[2](context.c.o)
[build] _glfwSwapBuffers in libraylib.a[2](context.c.o)
[build] _glfwGetProcAddress in libraylib.a[2](context.c.o)
[build] __glfwInputKey in libraylib.a[4](input.c.o)
[build] __glfwInputKey in libraylib.a[4](input.c.o)
[build] __glfwInputKey in libraylib.a[4](input.c.o)
[build] __glfwInputKey in libraylib.a[4](input.c.o)
[build] __glfwInputKey in libraylib.a[4](input.c.o)
[build] ...
[build] ___asan_init, referenced from:
[build] _asan.module_ctor in libraylib.a[2](context.c.o)
[build] _asan.module_ctor in libraylib.a[3](init.c.o)
[build] _asan.module_ctor in libraylib.a[4](input.c.o)
[build] _asan.module_ctor in libraylib.a[5](monitor.c.o)
[build] _asan.module_ctor in libraylib.a[6](platform.c.o)
[build] _asan.module_ctor in libraylib.a[7](vulkan.c.o)
[build] _asan.module_ctor in libraylib.a[8](window.c.o)
[build] ...
[build] ___asan_memcpy, referenced from:
[build] __glfwRefreshContextAttribs in libraylib.a[2](context.c.o)
[build] _glfwInit in libraylib.a[3](init.c.o)
[build] _glfwInit in libraylib.a[3](init.c.o)
[build] _glfwInitAllocator in libraylib.a[3](init.c.o)
[build] _parseMapping in libraylib.a[4](input.c.o)
[build] _parseMapping in libraylib.a[4](input.c.o)
[build] _glfwUpdateGamepadMappings in libraylib.a[4](input.c.o)
[build] _glfwUpdateGamepadMappings in libraylib.a[4](input.c.o)
[build] _glfwUpdateGamepadMappings in libraylib.a[4](input.c.o)
[build] ...
[build] ___asan_memmove, referenced from:
[build] __glfwInputMonitor in libraylib.a[5](monitor.c.o)
[build] __glfwInputMonitor in libraylib.a[5](monitor.c.o)
[build] _stbi_zlib_compress in libraylib.a[27](rtextures.c.o)
[build] _stbi_zlib_compress in libraylib.a[27](rtextures.c.o)
[build] _stbi_write_png_to_mem in libraylib.a[27](rtextures.c.o)
[build] _stbi_write_png_to_mem in libraylib.a[27](rtextures.c.o)
[build] _stbi_write_png_to_mem in libraylib.a[27](rtextures.c.o)
[build] ...
[build] ___asan_memset, referenced from:
[build] __glfw_calloc in libraylib.a[3](init.c.o)
[build] _glfwInit in libraylib.a[3](init.c.o)
[build] _terminate in libraylib.a[3](init.c.o)
[build] _terminate in libraylib.a[3](init.c.o)
[build] _glfwInitAllocator in libraylib.a[3](init.c.o)
[build] __glfwFreeJoystick in libraylib.a[4](input.c.o)
[build] _glfwUpdateGamepadMappings in libraylib.a[4](input.c.o)
[build] ...
...
build] clang: error: linker command failed with exit code 1 (use -v to see invocation)
[build] ninja: build stopped: subcommand failed.
[proc] The command: /opt/homebrew/bin/cmake --build /Users/dev/Documents/Projects/BASE_lib_c_vcpkg/build --config Debug --target all -- exited with code: 1
[driver] Build completed: 00:00:00.327
[build] Build finished with exit code 1
Solution
It looks like your library was compiled with the address sanitizer, so your application needs to be as well. You can add -fsanitize=address
to the options.
I wonder though if you really wanted to compile the library that way. Unless you are a developer of that library, you're probably not interested in looking for bugs in it. Compiling with the sanitizer will significantly slow down the library. You may want to figure out how it was compiled with the sanitizer, and build it again without.
Answered By - Mark Adler Answer Checked By - Timothy Miller (WPSolving Admin)