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?
Related
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've had to deal with plenty of libtool errors previously, but I really don't know what to do with one that doesn't give me a hint.
Here is the full error:
Libtool /Users/programmingstation7/Library/Developer/Xcode/DerivedData/RZFramework-fglhxeoyynfgoxgrgpqwrywuaexk/Build/Products/Debug-iphoneos/libRZFramework.a normal armv7
cd /Users/programmingstation7/Documents/CleanedFramework
setenv IPHONEOS_DEPLOYMENT_TARGET 5.0
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool -static -arch_only armv7 -syslibroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -L/Users/programmingstation7/Library/Developer/Xcode/DerivedData/RZFramework-fglhxeoyynfgoxgrgpqwrywuaexk/Build/Products/Debug-iphoneos -L/Users/programmingstation7/Documents/CleanedFramework/.. -filelist /Users/programmingstation7/Library/Developer/Xcode/DerivedData/RZFramework-fglhxeoyynfgoxgrgpqwrywuaexk/Build/Intermediates/RZFramework.build/Debug-iphoneos/RZFramework.build/Objects-normal/armv7/RZFramework.LinkFileList -lxml2 -ObjC -all_load -framework CoreData /Users/programmingstation7/Library/Developer/Xcode/DerivedData/RZFramework-fglhxeoyynfgoxgrgpqwrywuaexk/Build/Products/Debug-iphoneos/libarc.a /Users/programmingstation7/Library/Developer/Xcode/DerivedData/RZFramework-fglhxeoyynfgoxgrgpqwrywuaexk/Build/Products/Debug-iphoneos/libEISRenderHelpful.a -framework CFNetwork -framework MobileCoreServices -framework Security /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/libxml2.dylib /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/libz.dylib -framework CoreLocation -framework CoreText -framework UIKit -framework Foundation -framework CoreGraphics -framework MediaPlayer -framework QuartzCore -framework AVFoundation -framework OpenGLES -framework MapKit -framework MessageUI -framework SystemConfiguration -framework EventKit -framework EventKitUI -o /Users/programmingstation7/Library/Developer/Xcode/DerivedData/RZFramework-fglhxeoyynfgoxgrgpqwrywuaexk/Build/Products/Debug-iphoneos/libRZFramework.a
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool failed with exit code 1
I'm using the linker flags -lxml2 -ObjC -all_load
Any ideas as to what causes a exception-less libtool failure?
Oh, and I'm building a static library target. Previously, this was an app and I tore out all the unreusable stuff for the beginning of an app framework I'll be able to use.
I've had exactly the same problem yesterday and I found the solution.
remove the -lxml2 from your other linker flags.
It makes libtool link the library statically which causes problems.
In my current project I am unable to set the "Other Linker Flags" as I have in others projects. No matter what I put in the "Other Link Flags" section of my xcode project settings it does not show up in the detailed build log, and the desired linking does not happen:
Ld build/Debug-iphonesimulator/MyProject.app/MyProject normal i386
cd /Users/theUser/Development/xm8vc/MyProject/trunk
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/g++-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk -L/Users/theUser/Development/xm8vc/MyProject/trunk/build/Debug-iphonesimulator -L/Users/theUser/Development/xm8vc/MyProject/trunk -F/Users/theUser/Development/xm8vc/MyProject/trunk/build/Debug-iphonesimulator -F/Users/theUser/Development/xm8vc/MyProject/trunk -filelist /Users/theUser/Development/xm8vc/MyProject/trunk/build/MyProject.build/Debug-iphonesimulator/MyProject.build/Objects-normal/i386/MyProject.LinkFileList -mmacosx-version-min=10.6 -lxml2 -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework CoreGraphics -framework CoreData -framework QuartzCore -framework AVFoundation -framework AddressBook -framework AddressBookUI -framework AudioToolbox -framework OpenGLES -framework CFNetwork -framework SystemConfiguration -framework MediaPlayer -lxml2 -lz -framework SpeechKit -o /Users/theUser/Development/xm8vc/MyProject/trunk/build/Debug-iphonesimulator/MyProject.app/MyProject
Is there something that would cause xcode to ignore the "Other Linker Flags?"
Where are you setting these flags? You can set flags like this at various levels in your project - project settings, target settings, etc. There's a full description in Working with Xcode Build Settings. It's possible that, for example, you are setting it in your project settings, and then it is being overridden by your target settings.
I have configure wxWidgets in my MAC OS. In terminal my program in working fine. Here is the following command which I use to run.
gcc -o main main.cpp -I/usr/lib/wx/include/mac-unicode-debug-2.8 -I/usr/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXDEBUG__ -D__WXMAC__ -framework IOKit -framework Carbon -framework Cocoa -framework System -framework QuickTime -framework OpenGL -framework AGL -lwx_macud-2.8
How can I configure xcode so that it pass the Header & libs to GCC.
In XCode, bring up the Inspector for the target, look at the "Build" tab, search for "header" and "library". You'll find the relevant configuration options.
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.