Unable to run SFML project with CMake on arm64 - c++

I am using MacBook with M1 and I try to create a project with SFML.
I downloaded a snapshot of SFML with files built for arm64
I verified it using file command
Example:
libsfml-graphics.dylib: Mach-O 64-bit dynamically linked shared library arm64
I placed these files in ~/Library/Frameworks along with extlibs directory content.
I set a CMake flag: -DCMAKE_OSX_ARCHITECTURES=arm64
But I still am unable to run this project.
Error:
[ 50%] Linking CXX executable myProject
Undefined symbols for architecture arm64:
"__ZN2sf6StringC1EPKcRKSt6locale", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
make[3]: *** [myProject] Error 1
make[2]: *** [CMakeFiles/myProject.dir/all] Error 2
make[1]: *** [CMakeFiles/myProject.dir/rule] Error 2
make: *** [myProject] Error 2
This is my whole CMakeLists.txt file:
cmake_minimum_required(VERSION 3.19)
project(myProject)
add_executable(myProject main.cpp)
set(CMAKE_CXX_COMPILER "/opt/homebrew/bin/g++-11" CACHE STRING "C++ compiler" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCMAKE_OSX_ARCHITECTURES=arm64")
include_directories(/usr/local/include)
find_package(SFML 2.5 COMPONENTS system window graphics network audio REQUIRED)
include_directories(${SFML_INCLUDE_DIRS})
target_link_libraries(myProject sfml-system sfml-window sfml-graphics sfml-audio sfml-network)
I also tried to use dylib instead of framework, but it was unsuccessful also. I'd be grateful for any help, I can't figure out what I did wrong.

Related

Undefined symbols using WxWidgets and Conan

I am trying to adopt the Conan C++ package manager. I have followed along with the getting started have managed to get it working with most projects. However I am having linking issues with WxWidgets that I can't seem to fix.
linker error:
[ 23%] Linking CXX executable ../bin/wx_sample
Undefined symbols for architecture x86_64:
"Frame::onMenuFileQuit(wxCommandEvent&)", referenced from:
__GLOBAL__sub_I_frame.cpp in frame.cpp.o
"Frame::onMenuFileSave(wxCommandEvent&)", referenced from:
__GLOBAL__sub_I_frame.cpp in frame.cpp.o
"Frame::onMenuFileAbout(wxCommandEvent&)", referenced from:
__GLOBAL__sub_I_frame.cpp in frame.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/wx_sample] Error 1
make[1]: *** [src/CMakeFiles/wx_sample.dir/all] Error 2
make: *** [all] Error 2
conanfile.txt
[requires]
wxwidgets/3.1.4#bincrafters/stable
[generators]
cmake
CmakeFile.txt - project root -
cmake_minimum_required(VERSION 3.17)
project(wx_sample)
set(CMAKE_CXX_STANDARD 17)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
include_directories(src)
add_subdirectory(src)
CmakeFile.txt -- src folder --
set(BINARY ${CMAKE_PROJECT_NAME})
file(GLOB_RECURSE SOURCES LIST_DIRECTORIES true *.h *.cpp)
set(SOURCES ${SOURCES})
add_executable(${BINARY} ${SOURCES})
target_link_libraries(${BINARY} ${CONAN_LIBS})
conan default profile:
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=apple-clang
compiler.libcxx=libc++
compiler.version=12.0
os=Macos
os_build=Macos
I am not sure if I need to include deps into my conanfile, though I thought that Conan manages this automatically? If I remove the offending sections listed in the error, the application links successfully.
EDIT:
You were right on the CONAN_LIBS global. Your CMake structure looks fine. You could try to call conan_basic_setup() from the src CMakeLists.txt.
If that doesn't work the issue might be in your conanfile.py.
https://github.com/bincrafters/conan-wxwidgets/commit/37b6669229ec0e68593065a700c360d23a914bac

Why is thread sanitizer option not building?

I have the following CMake file on osx using IntelliJ/CLion:
cmake_minimum_required(VERSION 3.9)
project(GrepUtil)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z -fsanitize=thread -Wall")
set(SOURCE_FILES main.cpp)
add_executable(GrepUtil ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} stdc++fs)
While building it, I am getting the following errors:
[ 50%] Building CXX object CMakeFiles/GrepUtil.dir/main.cpp.o
[100%] Linking CXX executable GrepUtil
Undefined symbols for architecture x86_64:
"___tsan_atomic32_fetch_add", referenced from:
__gnu_cxx::__exchange_and_add(int volatile*, int) in main.cpp.o
"___tsan_atomic8_load", referenced from:
...
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[3]: *** [GrepUtil] Error 1
make[2]: *** [CMakeFiles/GrepUtil.dir/all] Error 2
make[1]: *** [CMakeFiles/GrepUtil.dir/rule] Error 2
I am using g++-7 (7.1.0) compiler. Program builds fine without the sanitize option. Is tsan supported with/on Sierra?

linker can't find libraries although defined in CMakeLists.txt

I'm quite new to work with cmake, and there is a problem I can't find the solution to:
I use the vtk library and specify this in the CMakeLists.txt file:
cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
cmake_policy(SET CMP0053 OLD)
project (pcl-visualizer)
find_package (Qt4 REQUIRED)
find_package (VTK REQUIRED)
find_package (PCL 1.7.1 REQUIRED)
include_directories (${PCL_INCLUDE_DIRS})
link_directories (${PCL_LIBRARY_DIRS})
add_definitions (${PCL_DEFINITIONS})
set (project_SOURCES main.cpp pclviewer.cpp)
set (project_HEADERS pclviewer.h)
set (project_FORMS pclviewer.ui)
set (VTK_LIBRARIES vtkRendering vtkGraphics vtkHybrid QVTK)
QT4_WRAP_CPP (project_HEADERS_MOC ${project_HEADERS})
QT4_WRAP_UI (project_FORMS_HEADERS ${project_FORMS})
INCLUDE (${QT_USE_FILE})
ADD_DEFINITIONS (${QT_DEFINITIONS})
ADD_EXECUTABLE (pcl_visualizer ${project_SOURCES}
${project_FORMS_HEADERS}
${project_HEADERS_MOC})
TARGET_LINK_LIBRARIES (pcl_visualizer ${QT_LIBRARIES} ${PCL_LIBRARIES} ${VTK_LIBRARIES})
cmake also runs fine. It gives no error so I assume it can find all libraries, including the vtk library?
When I run make though, I get this error message:
[ 16%] Linking CXX executable pcl_visualizer
/usr/bin/ld: cannot find -lvtkRendering
/usr/bin/ld: cannot find -lvtkGraphics
/usr/bin/ld: cannot find -lvtkHybrid
/usr/bin/ld: cannot find -lQVTK
/usr/bin/ld: cannot find -lvtkRendering
/usr/bin/ld: cannot find -lvtkGraphics
/usr/bin/ld: cannot find -lvtkHybrid
/usr/bin/ld: cannot find -lQVTK
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/pcl_visualizer.dir/build.make:410: pcl_visualizer] Error 1
make[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/pcl_visualizer.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I installed the vtk library via the package manager (pacman, I run arch linux), so it should be in one of the standard directories?
I checked if the right libraries are installed via pacman -Q vtk and it lists all needed libraries in the `/usr/lib/`` directory.

Undefined symbols when building libuv

I need to use libuv with my library. Since I cannot link it two static libraries I decided to include the source for libuv along with my code. I have a .cmake file that downloads libuv, checks out the right tag and adds the source files to a variable:
include(DownloadProject.cmake)
download_project(PROJ libuv
GIT_REPOSITORY https://github.com/libuv/libuv.git
GIT_TAG v1.10.0
${UPDATE_DISCONNECTED_IF_AVAILABLE}
)
exec_program(COMMAND "./autogen.sh" WORKING_DIRECTORY ${libuv_SOURCE_DIR})
exec_program(COMMAND "./configure" WORKING_DIRECTORY ${libuv_SOURCE_DIR})
include_directories(${LIBUVDIR}/include ${LIBUVDIR}/src)
set(LIBUV_SOURCES
${LIBUVDIR}/include/uv.h
${LIBUVDIR}/include/tree.h
${LIBUVDIR}/include/uv-errno.h
${LIBUVDIR}/include/uv-threadpool.h
${LIBUVDIR}/include/uv-version.h
${LIBUVDIR}/src/fs-poll.c
${LIBUVDIR}/src/heap-inl.h
${LIBUVDIR}/src/inet.c
${LIBUVDIR}/src/queue.h
${LIBUVDIR}/src/threadpool.c
${LIBUVDIR}/src/uv-common.c
${LIBUVDIR}/src/uv-common.h
${LIBUVDIR}/src/version.c
)
etc.
I then add add the list of libuv source files to the list of source files for my project and link the library with its dependencies:
include(libuv.cmake)
# Build library
set(SOURCE_FILES
<my sources>
${LIBUV_SOURCES})
add_library(databaseclient STATIC ${SOURCE_FILES})
set(CMAKE_THREAD_PREFER_PTHREAD 1)
set(THREADS_PREFER_PTHREAD_FLAG 1)
include(FindThreads)
target_link_libraries(databaseclient PUBLIC Threads::Threads)
But when I run make I get the following error:
Undefined symbols for architecture x86_64:
"_pthread_barrier_destroy", referenced from:
_uv_barrier_destroy in libdatabaseclient.a(thread.c.o)
"_pthread_barrier_init", referenced from:
_uv_barrier_init in libdatabaseclient.a(thread.c.o)
"_pthread_barrier_wait", referenced from:
_uv_barrier_wait in libdatabaseclient.a(thread.c.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [tests/unit_tests] Error 1
make[1]: *** [tests/CMakeFiles/unit_tests.dir/all] Error 2
make: *** [all] Error 2
unit_tests is my unit tests executable.
I think there's something I'm not linking against, just don't know what. Any clues?
Hi I just ran into this same problem, it seems pthread_barrier primitives are not implemented on MacOS despite it's claims of POSIX compliance. LibUV implements it's own versions using other threading primitives. If you add ${LIBUVDIR}/src/unix/pthread-barrier.c to your list of libuv c files it should link correctly.
Here is what I have in CMakeLists.txt for libuv
set(LIBUVDIR libuv)
include_directories(${LIBUVDIR}/include ${LIBUVDIR}/src)
set(SOURCES
${LIBUVDIR}/src/fs-poll.c
${LIBUVDIR}/src/inet.c
${LIBUVDIR}/src/threadpool.c
${LIBUVDIR}/src/uv-common.c
${LIBUVDIR}/src/version.c)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
add_definitions(-D_GNU_SOURCE)
set(SOURCES ${SOURCES}
${LIBUVDIR}/src/unix/linux-syscalls.c
${LIBUVDIR}/src/unix/linux-core.c
${LIBUVDIR}/src/unix/linux-inotify.c)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
add_definitions(-D_DARWIN_USE_64_BIT_INODE=1 -D_DARWIN_UNLIMITED_SELECT=1)
set(SOURCES ${SOURCES}
${LIBUVDIR}/src/unix/darwin.c
${LIBUVDIR}/src/unix/darwin-proctitle.c
${LIBUVDIR}/src/unix/fsevents.c
${LIBUVDIR}/src/unix/kqueue.c
${LIBUVDIR}/src/unix/pthread-barrier.c
${LIBUVDIR}/src/unix/proctitle.c)
endif()
include_directories(${LIBUVDIR}/src/unix)
set(SOURCES ${SOURCES}
${LIBUVDIR}/src/unix/async.c
${LIBUVDIR}/src/unix/core.c
${LIBUVDIR}/src/unix/dl.c
${LIBUVDIR}/src/unix/fs.c
${LIBUVDIR}/src/unix/getaddrinfo.c
${LIBUVDIR}/src/unix/getnameinfo.c
${LIBUVDIR}/src/unix/loop-watcher.c
${LIBUVDIR}/src/unix/loop.c
${LIBUVDIR}/src/unix/pipe.c
${LIBUVDIR}/src/unix/poll.c
${LIBUVDIR}/src/unix/process.c
${LIBUVDIR}/src/unix/signal.c
${LIBUVDIR}/src/unix/stream.c
${LIBUVDIR}/src/unix/tcp.c
${LIBUVDIR}/src/unix/thread.c
${LIBUVDIR}/src/unix/timer.c
${LIBUVDIR}/src/unix/tty.c
${LIBUVDIR}/src/unix/udp.c)
add_library(uv STATIC ${SOURCES})
target_link_libraries(uv pthread)

OpenGL hello.c fails to build using CMake

I am trying to build the hello.c example from http://www.glprogramming.com/red/chapter01.html (look for "Example 1-2").
My CMakeLists.txt is as follows:
cmake_minimum_required (VERSION 2.8)
project (GLUTEX)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
include_directories(${GLUT_INCLUDE_DIRS})
include_directories(${OpenGL_INCLUDE_DIRS})
add_executable (glutex glutex.c)
target_link_libraries (glutex ${OpenGL_LIBRARIES})
target_link_libraries (glutex ${GLUT_LIBRARIES})
The CMake call succeeds in generating the required Makefile. But when I call make, I encounter the following:
Scanning dependencies of target glutex
[100%] Building C object CMakeFiles/glutex.dir/glutex.c.o
Linking C executable glutex
/usr/bin/ld: CMakeFiles/glutex.dir/glutex.c.o: undefined reference to symbol 'glOrtho'
/usr/bin/ld: note: 'glOrtho' is defined in DSO /usr/lib64/libGL.so.1 so try adding it to the linker command line
/usr/lib64/libGL.so.1: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
make[2]: *** [glutex] Error 1
make[1]: *** [CMakeFiles/glutex.dir/all] Error 2
make: *** [all] Error 2
How do I fix this?
Try changing
target_link_libraries (glutex ${OpenGL_LIBRARIES})
to
target_link_libraries (glutex ${OPENGL_LIBRARIES})