SFML 2.1 Undefined symbols for architecture x86_64 error - c++

I have recently installed SFML 2.1 and am trying to compile and run from the terminal, NOT Xcode, the sample program that they have on their website at http://www.sfml-dev.org/tutorials/2.0/start-linux.php.
Path to where I installed SFML:
/Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal
However, I keep getting the error of:
Undefined symbols for architecture x86_64:
"sf::String::String(char const*, std::__1::locale const&)", referenced from:
_main in window-48cb4a.o
After googling it, I came across this question: SFML 2.1 RenderWindow linking error
In the accepted answer, the person said that if I wanted to use g++, I had to download the "GCC" version. So, I proceeded to download the GCC - universal 32+64 bits (OS X 10.5+) version and then followed the instructions for installing and compiling SFML on linux, since there were none for mac (http://www.sfml-dev.org/tutorials/2.0/start-linux.php) by doing the following:
Since I had installed SFML in a non-standard location, I told my compiler where to find the header files like so:
-I /Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/Frameworks/SFML.framework/Headers
I also had to tell my compiler where to find the SMFL libraries:
-L /Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/lib
I needed to also tell the library loader where to find the SFML libraries from:
export LD_LIBRARY_PATH=/Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/lib
Then, I put the sfml-audio.framework, sfml-window.framework, sfml-graphics.framework, sfml-network.framework, and sfml-system.framework in my Frameworks directory (/Library/Frameworks).
Finally, I tried to compile my program in the following ways:
g++ window.cpp -I /Users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/Frameworks/SFML.framework/Headers/SFML -L /users/.../Desktop/C++_Code/SMFL/SFML-2.1-osx-gcc-universal/lib -framework sfml-graphics -framework sfml-window -framework sfml-system
g++ window.cpp -framework sfml-graphics -framework sfml-window -framework sfml-system
But, I keep getting the same error. I have continued to google the error, but all I keep getting are questions where people are using Xcode and not the terminal. Any help would be greatly appreciated!

I figured it out at last! First off, as Joachim Pileborg pointed out, I need to install the clang version of SFML for mac since I was using g++ to compile which is clang++ in disguise, as Joachim Pileborg also pointed out. Next, I had to go through the instructions again for setting up SFML with Linux (http://www.sfml-dev.org/tutorials/2.0/start-linux.php).
However, the icing on the cake was when I read this question:
OSX GCC how to specify sfml library source?
...and this question:
FreeType error when building in XCode
...which got me thinking: maybe I should try moving my freetype.framework folder (which can be found in the extlibs directory) into my /Library/Frameworks directory. Once I did this and compiled using
g++ window.cpp -framework sfml-graphics -framework sfml-window -framework sfml-system
It compiled and ran successfully!!! I am very happy now!

Related

GLFW C++ Undefined symbols for architecture x86_64 [duplicate]

I'm using G++ to link my project to glew32, glfw, opengl32, glu32, etc, everything compiles fine - however at the link stage everything but glViewport links and I get this error:
undefined reference to '_glViewport'.
I find this... odd since everything else was fine and I'm kinda at a loss for what to do. I look forward to any advice on what to try and or do.
As per my comment, you need to link with the OpenGL libraries, when you compile do (Linux/cygwin)
g++ -o target source.c -lGL
To link against the the OpenGL libs on Mac OSX it is
g++ -o target source.c -framework OpenGL

GCC 5.4 linker error after upgrading to Xcode 8

Recently I updated to XCode Version 8.0 (8A218a) on El Capitan (OS X 10.11 using Macports 2.3.4), and ever since, I have been getting the following link error when I try to compile my project inside Qt Creator.
/opt/local/bin/g++-mp-5 -headerpad_max_install_names -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.8 -Wl,-rpath,/Users/zero/builds/Qt5.7.0/5.7/clang_64/lib -o uniMR.app/Contents/MacOS/uniMR ALL_OBJECT_FILES_GO_HERE.o -F/Users/zero/builds/Qt5.7.0/5.7/clang_64/lib -L/opt/local/lib -L/usr/local/lib -funit-at-a-time -fopenmp -lmlpack -larmadillo -framework CoreFoundation -DNDEBUG -lpthread -lALL_ITK_LIBS_GO_HERE -framework QtOpenGL -framework QtWidgets -framework QtGui -framework QtCore -framework DiskArbitration -framework IOKit -framework QtXml -framework OpenGL -framework AGL
**ld: unexpected token: !tapi-tbd-v2 file '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd' for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [uniMR.app/Contents/MacOS/uniMR] Error 1**
I am compiling the main project with gcc 5.4 (not clang) inside QtCreator (Qt 5.7), and all my dependent libraries (ITK, BOOST, etc) are compiled using gcc 5.4 as well. I also recompiled all my dependent libraries after upgrading XCode, but that did not help either. I could find only one post that is related to the error I am seeing, but it doesnt seem useful:
https://trac.macports.org/ticket/51701
All was fine before I upgraded XCode. Now I am not sure how to fix the issue. I would appreciate any help on this. Thanks.
UPDATE:
This doesnt seem like a problem with any of the external libraries I am linking with. This is what I did. I created a new "QT widgets application" in QtCreator, and chose to compile with gcc5. I get the same error ld: unexpected token: !tapi-tbd-v2. If I switch to clang, then there is no error.
I had this "ld: unexpected token: !tapi-tbd-v2" error building an unrelated project and was able to solve it by editing the .tbd file for the framework that was giving the error.
For me that file was:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate.tbd
I simply removed the entire line "--- !tapi-tbd-v2" while building, and then put it back once finished.
had yesterday the same problem. I had XCode 7.3 and 8 on my system. Removing 7.3 and moving 8 into the apps location solved the problem.
I had the same problem. I used macport's GCC 6 as compiler and linker. It seems the GCC doesn't understand the new tbd format. In the MacOSX SDK path, there are now only these tbd text files which contain info about the real dylib libraries. So I just symlinked the real libraries to the SDK paths beside their tbd files. Then GCC can directly use the real libraries without parsing tbd files.
Here is a script for creating those symlinks:
https://gist.github.com/michalfapso/9abdbd5669bfdc4cd1a2179824d299e9
I had the same problem while compiling with opam.
The workaround was PATH=/usr/bin:$PATH, thus gcc will resolve to the default /usr/bin/gcc which is clang on macOS.

Linker error with GLFW on OS 10.10

I'm trying to compile the following
#include <GLFW/glfw3.h>
int main()
{
glfwInit();
return 0;
}
just to verify that my GLFW installation is working. I use the terminal with
clang++ -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo -I/opt/local/include/ test.c
but I receive a linker error for the glfwInit function:
Undefined symbols for architecture x86_64:
"_glfwInit", referenced from:
_main in test-d8c21e.o
ld: symbol(s) not found for architecture x86_64
I have installed glfw with sudo port install glfw and followed every possible tutorial I've found. I can verify that the libglfw.dylib file can be found at /opt/local/lib/ as (I think) it should.
Any suggestions?
You need to link with GLFW[3] as well, e.g., add:
-L/opt/local/lib -lglfw3
If you have the pkgconfig port installed, you can also take advantage of that with:
clang `pkg-config glfw3 --cflags` test.c -o test \
`pkg-config glfw3 --static --libs`
You may not need the --static flag if you have: libglfw3.dylib, as opposed to using: libglfw3.a, but it doesn't hurt.
If you are using Xcode, you must add the libglfw3.a library when linking binaries.
Heres the trick
Show hidden folders. Paste this into terminal: defaults write com.apple.finder AppleShowAllFiles YES
Relaunch a finder window and navigate to Macintosh HD\usr
Drag the usr folder to the "Favorites" side in the terminal
In xcode, click the add "+" to link binaries, then click "Add Other"
navigate to the libglfw3.a and add it!
If it still does not work, here are some instructions that helped me.
https://engineering-game-dev.com/2013/08/14/glfw-compiling-source-and-creating-an-xcode-project/comment-page-1/#comment-1400

Setup Xcode and FLTK

Errors I get when trying to build the first block of code on this page under Xcode
Undefined symbols for architecture x86_64:
"fl_define_FL_SHADOW_LABEL()", referenced from:
_main in main.o
I installed FLTK with homebrew by brew install FLTK and there were no errors:
/usr/local/Cellar/fltk/1.3.2_1: 315 files, 5.8M, built in 93 seconds
I realize this problem has been asked before, but the answer
You need to install it first as it's not on Mac OS X, using something like homebrew/macports/manually which will provide you with an installed copy that can be referenced using the User Header Search Paths and Library Search Paths, as well as referencing the fltk library(/ies) in the Linked Frameworks and Libraries
did not work for me or I got the specific file paths wrong. I have tried Xcode 5.1.1 and 6.0 and both have the same problem.
I have attached a screenshot of my build settings.
I have found the solution at groups.google.com and below is what I have done:
Change build settings as such:
Header Search Paths : -I/usr/local/include
Library Search Paths : /usr/local/lib
Go to terminal and type fltk-config --ldflags
You get a line of flags, mine was
-L/usr/local/Cellar/fltk/1.3.2_1/lib -lfltk -lpthread -framework Cocoa.
In Xcode Build settings, paste that in other linker flags
After these steps Xcode compiled the file successfully.

library not found for.....?

i added new framework(3rd party) and build.
Unfortunately, since the execution was not.
How do I solve this problem?
The whole four nights were spent.:(
Ld /Users/hansehee/Library/Developer/Xcode/DerivedData/iBaseballManager-dbrtdyfdzzunktexlyibuzjbftoy/Build/Products/Distribution-iphoneos/iBaseballManager.app/iBaseballManager normal armv7s
cd /DevLibs/BaseballManager_KOR/iBaseballManager
setenv IPHONEOS_DEPLOYMENT_TARGET 6.0
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch armv7s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -L/Users/hansehee/Library/Developer/Xcode/DerivedData/iBaseballManager-dbrtdyfdzzunktexlyibuzjbftoy/Build/Products/Distribution-iphoneos -L/DevLibs/BaseballManager_KOR/iBaseballManager/Classes/BaseballManager/kakaoUtil/kakao-ios-sdk -F/Users/hansehee/Library/Developer/Xcode/DerivedData/iBaseballManager-dbrtdyfdzzunktexlyibuzjbftoy/Build/Products/Distribution-iphoneos -filelist /Users/hansehee/Library/Developer/Xcode/DerivedData/iBaseballManager-dbrtdyfdzzunktexlyibuzjbftoy/Build/Intermediates/iBaseballManager.build/Distribution-iphoneos/iBaseballManager_Device.build/Objects-normal/armv7s/iBaseballManager.LinkFileList -dead_strip -fobjc-link-runtime -miphoneos-version-min=6.0 -framework StoreKit -framework SystemConfiguration -framework CoreData -weak_framework AdSupport -framework MediaPlayer -framework CoreTelephony -framework Security -lzlib -lstdc++ -lCxImage -lj2k -ljasper -lkakao-ios-sdk-i386-armv7-armv7s -ljbig -ljpeg -lpng -ltiff -framework AudioToolbox -framework AVFoundation -framework Foundation -framework UIKit -framework CoreGraphics -framework OpenAL -framework OpenGLES -framework QuartzCore -liClet -Xlinker -dependency_info -Xlinker /Users/hansehee/Library/Developer/Xcode/DerivedData/iBaseballManager-dbrtdyfdzzunktexlyibuzjbftoy/Build/Intermediates/iBaseballManager.build/Distribution-iphoneos/iBaseballManager_Device.build/Objects-normal/armv7s/iBaseballManager_dependency_info.dat -o /Users/hansehee/Library/Developer/Xcode/DerivedData/iBaseballManager-dbrtdyfdzzunktexlyibuzjbftoy/Build/Products/Distribution-iphoneos/iBaseballManager.app/iBaseballManager
ld: library not found for -lzlib
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Remove the reference to the library and add it again, it will solve the problem.
Use xcworkspace it will solve your problem.
I also faced same once I install cocoa pods; Close and launch with xcworkspace again will solve your problem.
Make sure you have added the necessary search path for your library in Library Search Paths in Build Settings.
There should be something like:
${SOURCE_ROOT}/Framework/Classes
For .a files you need to set Target Dependencies in Build Phases in section.
Just click "+" and add your .a file there.
Had the same problem and none of these answers fix it for me.
Problem was Pod project in workspace had the following config:
Build Active Architecture Only: YES
For that reason, when I wanted to build for i386 (Simulator), XCode did not build Pods projects, so it could not meet dependencies. As soon as I changed it to NO it started working
If anyone is here looking specifically for the "library not found for -lPods" error, this was solved by opening the workspace instead of the xcodeproject. Searching google for library not found for -lPods without quotes turns this SO post as the first result, whereas if you wrap the search in quotes you'll get a post with the answer I just gave.
I changed -all_load to -force_load
In Xcode goto select your project
Build Settings -> Search Paths -> Library Search Paths set the path with /usr/local/lib
note : make sure that you have added dylib at frameworks
OS X 10.11 Xcode7.0.1
my case:
library not found for -lPods-BlocksKit
error:linker command failed with exit code 1(use -v to see invocation)
I delete all pod related content, add "$(inherited)" then fix it.
Other Linker Flags image
my case: use cocoapods, open xcworkspace, and meet "library not found for -lPods-AFNetworking" error.
my solution: Preference -> Location -> Derived Data, click "Advanced" button -> choose 'shared Folder'. (when meet error, the original location is Legacy).
None of the above solutions worked for me, so I downloaded the missing library:
https://github.com/danielctull-forks/GoogleAnalytics-SDK-iOS
7.3.1 Pods 1.0.0
Had same stuff today, after cocoapods update from 0.39.0 to 1.0.0.
Had an error : "ld: library not found -lPods".
I've got linked two "Pod" libs, accidentally. One was lPods, and other was lPods-ProjectName. I deleted "libPods.a: from Project>General>Linked Frameworks and Libraries
AND! I changed Pods>Build Active Build Architecture to NO, of course.
And it worked.