I have a mac and I am trying to compile my projects. The standard on the wiki: g++ sdl.cpp -lSDLmain -lSDL -framework Cocoa does not seem to be working it returns that it cannot find -lSDL and -lSDLmain. Any help would be greatly appreciated.
Do you understand the meaning of the flags? The linker is looking for the libraries SDL and SDLmain, are they setup on your machine?
For me the solution is as follows:
g++ -c -I/Library/Frameworks/SDL.framework/Headers -I. -I.. -I/Library/Frameworks/SDL_image.framework/Headers -I/Library/Frameworks/SDL_mixer.framework/Headers -I/Library/Frameworks/SDL_ttf.framework/Headers -I/Library/Frameworks/SDL_net.framework/Headers -I/usr/local/include/SDL -I/usr/local/include/ ./lesson20.cpp -o ./lesson20.o
Now that the object file has been created, we can use this solution:
g++ -L/usr/local/lib -I/Library/Frameworks/SDL.framework/Headers -I. -I.. -I/Library/Frameworks/SDL_image.framework/Headers -lSDLmain -I/Library/Frameworks/SDL_mixer.framework/Headers -I/Library/Frameworks/SDL_ttf.framework/Headers -I/Library/Frameworks/SDL_net.framework/Headers -framework SDL -framework SDL_image -framework Cocoa -framework SDL_mixer -framework SDL_ttf -framework SDL_net -framework OpenGL lesson20.o -o Lesson
This solution assumes that you have the SDL_image, SDL_mixer, SDL_ttf, and SDL_net frameworks installed in the '/Library/Frameworks/' directory.
Since this is difficult to attempt by hand, and the solution is a little messy, it's better to simply write a script to do all of this for you.
The '-I' (capital i) flag tells the compiler where to look for headers. The '-L' flag tells the compiler where to look for libraries. The '-l' (lower case L) flag tells the compiler which libraries to use. The '-framework' flag basically behaves like a '-l' (lower case L) flag.
Related
Using makefile, I attempted to link the glfw3 library manually. This is my directory:
+root
+include
+GLFW
glfw3.h
glfw3native.h
+lib
+GLFW
libglfw.3.dylib
libglfw3.a
+src
main.cpp
Makefile
My makefile compiles and builds an executable when I place this in my flags:
LDFLAGS = -Llib/GLFW
LDLIBS = -lglfw3 -framework Cocoa -framework OpenGL -framework IOKit
but says error when I modify a little:
LDFLAGS = -Llib
LDLIBS = -lGLFW/glfw3 -framework Cocoa -framework OpenGL -framework IOKit
#error :library not found for -lGLFW/glfw3
or this:
LDFLAGS = -Llib
LDLIBS = -lglfw3 -framework Cocoa -framework OpenGL -framework IOKit
#error :library not found for -lglfw3
This is quite strange frankly. Some questions to be asked:
Is there a reason why the first is preferred?
Does -Llib find all libraries inside the directory lib, even if there is another inner directory that contains them?
I am new to C++ compiling/linking.
I am trying to link all libraries statically with gcc, I tried using LDFLAGS=-static but did not work. Error message showed:
/bin/sh ./libtool --tag=CXX --mode=link /home/dizhang/lib/hdf5/bin/h5c++ -g -O2 -L/home/dizhang/lib/blitz/lib -L/home/dizhang/lib/libconfig/lib -o angora src/libangora.la -lblitz -lconfig++
libtool: link: /home/dizhang/lib/hdf5/bin/h5c++ -g -O2 -o angora -L/home/dizhang/lib/blitz/lib -L/home/dizhang/lib/libconfig/lib src/.libs/libangora.a -L/bgsys/drivers/V1R2M2/ppc64/comm/lib64 -L/bgsys/drivers/V1R2M2/ppc64/comm/lib -L/bgsys/drivers/V1R2M2/ppc64/spi/lib -lpthread -lm /home/dizhang/lib/blitz/lib/libblitz.a /bgsys/drivers/V1R2M2/ppc64/comm/lib/libmpichcxx-gcc.so /bgsys/drivers/toolchain/V1R2M2_base/gnu-linux/powerpc64-bgq-linux/lib/libstdc++.so /bgsys/drivers/V1R2M2/ppc64/comm/lib/libmpich-gcc.so /bgsys/drivers/V1R2M2/ppc64/comm/lib/libopa-gcc.so /bgsys/drivers/V1R2M2/ppc64/comm/lib/libmpl-gcc.so /home/dizhang/lib/libconfig/lib/libconfig++.a /bgsys/drivers/toolchain/V1R2M2_base-efix014/gnu-linux/powerpc64-bgq-linux/lib/libstdc++.so -Wl,-rpath -Wl,/bgsys/drivers/toolchain/V1R2M2_base-efix014/gnu-linux/powerpc64-bgq-linux/lib -Wl,-rpath -Wl,/bgsys/drivers/V1R2M2/ppc64/comm/lib -Wl,-rpath -Wl,/bgsys/drivers/toolchain/V1R2M2_base/gnu-linux/powerpc64-bgq-linux/lib -Wl,-rpath -Wl,/bgsys/drivers/toolchain/V1R2M2_base-efix014/gnu-linux/powerpc64-bgq-linux/lib -Wl,-rpath -Wl,/bgsys/drivers/V1R2M2/ppc64/comm/lib -Wl,-rpath -Wl,/bgsys/drivers/toolchain/V1R2M2_base/gnu-linux/powerpc64-bgq-linux/lib
/bgsys/drivers/toolchain/V1R2M2_base-efix014/gnu-linux/lib/gcc/powerpc64-bgq-linux/4.4.7/../../../../powerpc64-bgq-linux/bin/ld: attempted static link of dynamic object `/bgsys/drivers/V1R2M2/ppc64/comm/lib/libmpichcxx-gcc.so'
collect2: ld returned 1 exit status
I did some search and found that, telling Makefile -Wl -Bstatic may solve this problem, but how exactly I should change this in my Makefile?
I tried searching -Wl in Makefile but it was not in the text.
Thanks,
Di
Looks like you are trying to build HDF5 with MPI support on BGQ.
As long as you end up passing a ".so" version of a lib to gcc on BGQ -- you will see this error. You may need to check how you are passing MPI info to HDF5's configure script.
In my case (building another project that uses CMake) passing BGQ's MPI compiler wrappers to CMake always created a problem where it would try to link MPI using the shared libs instead of the static ones. To resolve this, I had to make sure to explicitly specify the ".a" variants of the MPI libs.
I have a problem with linking a compiled program (see github repo for details).
The osx specific makefile section is here:
CFLAGS = -v -arch x86_64 -Wall -fPIC -O2 -I./include $(OPTS)
LDFLAGS = -v -arch x86_64 -lpthread /usr/local/lib/libportaudio.a -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework Carbon
EXECUTABLE ?= squeezelite-osx
include Makefile
The compilation works fine, but during the linking it fails with:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.2.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.11.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -o squeezelite-osx main.o slimproto.o buffer.o stream.o utils.o output.o output_alsa.o output_pa.o output_stdout.o output_pack.o decode.o flac.o pcm.o mad.o vorbis.o faad.o mpg.o dsd.o dop.o dsd2pcm/dsd2pcm.o process.o resample.o -lpthread /usr/local/lib/libportaudio.a -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework Carbon -lFLAC -lmad -lvorbisfile -lfaad -lmpg123 -lsoxr -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/lib/darwin/libclang_rt.osx.a
ld: library not found for -lFLAC
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [squeezelite-osx] Error 1
The library which is not found is in the folder /usr/local/include and I think I have to add this path to the include path of the linker.
How can I add the path /usr/local/include to the include path of the linker?
The linker doesn't use include files; that's the compiler (actually the pre-processor, but let's keep it simple).
Instead you need to tell the linker that it should look in /usr/local/lib using the -L option:
-L/usr/local/lib
Note: you can provide more than one -L option to the linker.
I have used CMake 3.3.0-rc4 to generate an Xcode project for OpenTrack. However, when I attempt to build the ALL_BUILD target in Xcode 6.4, I immediately get the error below.
Libtool build/Debug/libopentrack-version.a normal x86_64
cd /Users/david/Documents/Programming/OpenTrack
export MACOSX_DEPLOYMENT_TARGET=10.10
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only x86_64 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -L/Users/user/Documents/Programming/OpenTrack/build/Debug -filelist /Users/user/Documents/Programming/OpenTrack/build/opentrack.build/Debug/opentrack-version.build/Objects-normal/x86_64/opentrack-version.LinkFileList -stdlib=libc++ -framework Cocoa -framework CoreFoundation -lobjc -lz -framework Carbon -o /Users/user/Documents/Programming/OpenTrack/build/Debug/libopentrack-version.a
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: unknown option character `t' in: -stdlib=libc++
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table <filename>] [-seg_addr_table_filename <file_system_path>] [-all_load] [-noall_load]
The Build Settings for the project has the following set for Linking / Other Librarian Flags:
OTHER_LIBTOOLFLAGS = -stdlib=libc++ -framework Cocoa -framework CoreFoundation -lobjc -lz -framework Carbon
From the libtool usage statement above, it looks to me like this set of options was generated for an entirely different version of libtool. What can I do (if anything) to get this project to build with the current version of Xcode?
You cannot use the flag -stdlib=libc++ or -framework with libtool, as they are valid only in the linker, so you should make OTHER_LIBTOOLFLAGS empty as none of those options apply
I am trying to compile a sfml project via command line under mac osx. Currently, I'm not able to get it to compile. Any help guys?
For the simple window application they include as part of the templates. I was able to compile it with the following command.
g++ -framework OpenGL -framework SFML -framework SFML-window main.cpp
I hope that helps
You can compile with only one instruction:
g++ -framework sfml-window -framework sfml-graphics -framework sfml-system main.cpp -o main