libSDL, CMake and Mac OS X lion 2 - macos

I'm trying to compile a cmake project on my mac, but it depends on the SDL.
I have alreaday read "LibSDL, CMake and MacOSX Lion", however I couldn't solve this problem.
CMakeList.txt
cmake_minimum_required(VERSION 2.6.4 FATAL_ERROR)
# Give a name to the project.
project(movehead)
# This include enable you to use our CMake framework
find_package(qibuild)
find_package(SDL REQUIRED)
link_directories( /usr/local/lib )
link_libraries (
${SDL_LIBRARY}
SDLmain
)
# Create an executable named movehead,
# with the source file : movehead.cpp
qi_create_bin(movehead movehead.cpp)
# Tell CMake that movehead depends on ALCOMMON.
# This will set the libraries to link movehead with,
# the include paths, and so on
qi_use_lib(movehead ALCOMMON)
Commandline
sudo qibuild make -c naoqi-sdk movehead Active configuration: naoqi-sdk (Debug)
Building movehead in naoqi-sdk (Debug)
Scanning dependencies of target movehead
Linking CXX executable sdk/bin/movehead
ld: warning: ignoring file /usr/local/lib/libSDLmain.a, file was built for archive which is not the architecture being linked (i386)
ld: warning: ignoring file /usr/local/lib/libSDL.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
Undefined symbols for architecture i386:
"_main", referenced from:
start in crt1.10.6.o
(maybe you meant: _SDL_main)
"_SDL_Init", referenced from:
_SDL_main in movehead.cpp.o
"_SDL_NumJoysticks", referenced from:
_SDL_main in movehead.cpp.o
"_SDL_JoystickEventState", referenced from:
_SDL_main in movehead.cpp.o
"_SDL_JoystickOpen", referenced from:
_SDL_main in movehead.cpp.o
"_SDL_JoystickName", referenced from:
_SDL_main in movehead.cpp.o
"_SDL_JoystickNumAxes", referenced from:
_SDL_main in movehead.cpp.o
"_SDL_PollEvent", referenced from:
_SDL_main in movehead.cpp.o
"_SDL_JoystickGetButton", referenced from:
_SDL_main in movehead.cpp.o
"_SDL_JoystickGetAxis", referenced from:
_SDL_main in movehead.cpp.o
"_SDL_QuitSubSystem", referenced from:
_SDL_main in movehead.cpp.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [sdk/bin/movehead] Error 1
make[1]: *** [CMakeFiles/movehead.dir/all] Error 2
make: *** [all] Error 2
[ERROR]
Error occured when building project movehead
dhcp47-122:movehead yukke150$ sudo qibuild configure -c naoqi-sdk movehead --disable-assembly
usage: qibuild [-h]
lipo -info /usr/local/lib/libSDL.dylib
Non-fat file: /usr/local/lib/libSDL.dylib is architecture: x86_64
lipo -info /usr/local/lib/libSDLmain.a
input file /usr/local/lib/libSDLmain.a is not a fat file
Non-fat file: /usr/local/lib/libSDLmain.a is architecture: x86_64
I think these file are x86_64.
How to fix?

Use the framework distribution of SDL (provided on SDL website) work for me to compile in either x86 or x86_64.
Previously I installed it from brew, so if same (or Mac Port, etc) don't forget to uninstall those first.

Related

Using igraph on OSX installed via homebrew

I am new for a C-programming and want to use igraph library.
I installed it via homebrew.
brew install igraph
After it i copy first example from igraph c tutorial in my main.cpp and change include igraph to
#include "igraph/igraph.h"
And Clion was suggest igraph functions and types.
Trying to build this a have error messages:
/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build
/Users/username/development/graph_clustring/cmake-build-debug --target
graph_clustring -- -j 4
[ 50%] Linking CXX executable graph_clustring
Undefined symbols for architecture x86_64:
"_igraph_destroy", referenced from:
_main in main.cpp.o
"_igraph_diameter", referenced from:
_main in main.cpp.o
"_igraph_erdos_renyi_game", referenced from:
_main in main.cpp.o
"_igraph_rng_default", referenced from:
_main in main.cpp.o
"_igraph_rng_seed", referenced from:
_main in main.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[3]: *** [graph_clustring] Error 1
make[2]: *** [CMakeFiles/graph_clustring.dir/all] Error 2
make[1]: *** [CMakeFiles/graph_clustring.dir/rule] Error 2
make: *** [graph_clustring] Error 2e
I think that I should fix my CMake file, and help CMake find lib isntalled via homebrew.
CMake file:
cmake_minimum_required(VERSION 3.8)
project(graph_clustring)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(graph_clustring ${SOURCE_FILES})
I was able to solve the problem by adding target_link_libraries command to a CMake. It should look like this
make_minimum_required(VERSION 3.8)
enter code here
project(graph_clustring)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(graph_clustring ${SOURCE_FILES})
target_link_libraries(graph_clustring, igraph.a)

Assembly executable on osx

I got nasm and I want to compile assembly into an executable. I keep getting the error:
ld: warning: ignoring file firststart.asm, file was built for unsupported file format which is not the architecture being linked (x86_64)
Undefined symbols for architecture x86_64:
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
when I try to compile with gcc. I am using gcc that comes with xcode. What am I doing wrong?

Linker error when compiling in Xcode

I am getting this error when I am compiling a program in Xcode.
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_MyDatabase", referenced from:
objc-class-ref in Gallery_CollectionViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
You have forgotten to add the source file that implements the class MyDatabase to the Xcode target and consequently it hasn't been compiled and linked with the binary.

gmp-chudnovsky.c and xcode 4.5

when I try to compile and run the gmp-chudnovsky.c file found here with xcode the following errors appear:
Undefined symbols for architecture x86_64:
"_fac_clear", referenced from:
_main in main.o
"_fac_compact", referenced from:
_fac_remove_gcd in main.o
"_fac_init", referenced from:
_main in main.o
"_fac_mul", referenced from:
_bs in main.o
"_fac_mul_bp", referenced from:
_bs in main.o
"_fac_resize", referenced from:
_fac_remove_gcd in main.o
"_fac_set_bp", referenced from:
_bs in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I know the gmp library is installed correctly as I have another xcode project linking to it that is compiling correctly. Any ideas as to why this is happening?
Forgot to say I have added paths to the header file and library for GMP as well as add the -lgmp flag under Other Linker Flags
SOLVED: see this answer.
I think xcode runs in a Debug configuration first, where no optimization is performed and no inlining is carried out. This means any inline function must also be made static.

Compiling C/C++ application using SDL in OS X, linking problem

I'm trying to compile a C/C++ program that uses SDL on a OS X 10.6.8 but I'm having some errors on the linking stage, the code compiles but fails to like due to some missing symbols. The error is:
Undefined symbols for architecture x86_64:
"_CFBundleGetMainBundle", referenced from:
-[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
_main in libSDLmain.a(SDLMain.o)
"_CFBundleCopyBundleURL", referenced from:
-[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
"_CFURLCreateCopyDeletingLastPathComponent", referenced from:
-[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
"_CFURLGetFileSystemRepresentation", referenced from:
-[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
"_CFRelease", referenced from:
-[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
...
"_OBJC_CLASS_$_NSAutoreleasePool", referenced from:
objc-class-ref in libSDLmain.a(SDLMain.o)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [dist/linwarrior] Error 1
I checked with the file command and the libraries are either x86_64 only or universal with both i386 and x86_64 versions.
Is there a way for me to determine what exactly is causing this error? A way to check the libs that are being included or any way to help debug the problem?
I don't know if it helps but this is what my Makefile creates, I removed file names to make it short, and the KNT flag is just something I'm using for preprocessor conditions:
/opt/local/bin/g++-mp-4.5 -DKNT=1 -Wp,-M,-MP,-MT,-MF, -std=c++0x -Wall -I source -O1 -funroll-loops -c -o
Thanks.

Resources