Trouble using SFML with GCC and OS X - c++

I've been trying to get SFML working for a while now and I've been trying to get it working using GCC. I'm on OS X by the way. I followed the standard Linux instructions and using the Linux 64-bit download however when it comes to compiling...
g++ -o testing main.cpp -lsfml-system
This happens:
main.cpp: In function ‘int main()’:
main.cpp:7: error: ‘class sf::Clock’ has no member named ‘GetElapsedTime’
main.cpp:9: error: ‘class sf::Clock’ has no member named ‘GetElapsedTime’
main.cpp:10: error: ‘Sleep’ is not a member of ‘sf’
So I thought it could be due to not using includes, so I changed my gcc compile command to:
g++ -o testing main.cpp -I ~/SFML-1.6/include/ -lsfml-system
and now I'm getting this error:
ld: warning: ignoring file /usr/local/lib/libsfml-system.so, file was built for unsupported file format which is not the architecture being linked (x86_64)
Undefined symbols for architecture x86_64:
"sf::Clock::Clock()", referenced from:
_main in ccZEiB7b.o
"sf::Clock::GetElapsedTime() const", referenced from:
_main in ccZEiB7b.o
"sf::Sleep(float)", referenced from:
_main in ccZEiB7b.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status**
And I have no idea what to do to fix it.

Short answer
Add the -arch i386 (on mac) or -m32 (on linux) flag
Long answer
Your sfml-system library was built in 32 bits whereas you are trying to compile your program in 64 bits. So your program cannot link to the library.
Recompile SFML in 64 bits if possible and you should be able to compile your program in 64 bits.

SFML expects you to use frameworks on OS X. Open the SFML folder and copy all the folders under lib64 to /Library/Frameworks (that is, copy SFML.framework, sfml-system.framework, etc. to /Library/Frameworks).
Once you've installed the frameworks, you can use them by passing the -framework command to g++ like so:
g++ -o testing main.cpp -framework SFML -framework sfml-system

Related

I'm trying to link hdf5 to c++ code (Mac)

I have the files:
main.cpp, tools.cpp, tools.h, integrator.cpp, and integrator.h.
I have tried to link HDF5 to this code (it compiles/links just fine without hdf5 stuff).
Here's what I am using to compile:
g++ -Wall -Werror -pedantic -std=c++1y -I /usr/local/include -L/usr/local/lib -lhdf5 -lhdf5_hl -lhdf5_cpp main.cpp tools.cpp integrator.cpp
The error I get is complete nonsense to me:
"__ZN2H56H5FileC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEjRKNS_17FileCreatPropListERKNS_15FileAccPropListE", referenced from:
_main in cc76aLiD.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
However, sure enough, if I take out all the HDF5 commands in my code but keep the #include "H5Cpp.h" at the top of main.cpp it works. This seems odd to me because I would assume it would fail here too?
Anyone have any suggestions to try?
I'm using a Mac if that is relevant. Thanks!
Maybe you want also link with -lhdf5_hl_cpp. If you had used cmake, as I suggested today, you would not have such issues.

ld: symbol(s) not found for architecture

First of all I want to say I realise this has been asked a dozen times, and I've read countless solutions without any luck so therefore I'm asking again.
I'm using OS X Mavericks 10.9.5, writing in Sublime 3 and compiling using terminal with g++
I'm trying to compile this simple file (test.cpp)
#include <iostream>
#include <SDL2/SDL.h>
int main () {
if(SDL_Init(SDL_INIT_VIDEO)) {
std::cout << "I made it this far" << std::endl;
}
return 0;
}
Compiler line :
g++ test.cpp
This returns the error :
Undefined symbols for architecture x86_64:
"_SDL_Init", referenced from:
_main in test-ebbae4.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
So, I've tried adding a lot of different flags, -m32 only changes the result to throw Undefined symbols for architecture i386: and ld: symbol(s) not found for architecture i386
I've tried different -arch variations, but I can't seem to get it to work. also played around with -l -I flags but I'm not sure I know what they do/how they could help..
Does anyone have a clue what to do next?
EDIT : Some additional information. I've tried using the .framework for SDL2, that didn't change anything, currently I'm using SDL2 installed through compilation of the source. Headers located in usr/local/SDL2
g++ test.cpp
You should specify the SDL library, too:
g++ test.cpp -lsdl2
You might need to include a path if its not well known to the compiler driver:
g++ test.cpp -L/path/to/the/library -lsdl2

C++ Compilation Issue - Undefined symbols for architecture x86_64 - Mac Os X Mountain Lion

I'm having a compilation issue which I'm unable to solve. I'm developing a cross platform C++ project coding on both Mac Os X 10.8 and Windows. The code compiles and run fine on Windows and on Mac Os X Leopard as well.
Since Apple pushes the developers to stick to the latest platform for various reasons I'm forced to develop on Mountain Lion and I'm trying to get the project to work again.
I compiled correctly all the libraries I needed (wxWidgets, etc) and I imported the project in the latest version of Eclipse. When I try to build the project it tries to compile the firts .cpp file and at the end it (why?) tries to invoke the linker resulting on a series of missing symbols for my own defined classes. None of the other .cpp files is being compiled, so it's pretty understendable why the whole process is failing.
I also tried to invoke make from CLI, with the same result. I went into the makefile and everything seems correct. It looks like a very newbie issue, I feel I'm missing something huge here.
I'm pasting below the output of the compiler, just in case some compiling guru step in. Please feel free to ask for more details.
Compiler output
Pastebin Link: Compiler output
I used PB since the output is quite large.
The relevant section are the invocation of as and collect2 soon after the compiling phase of the very first .cpp file. The missing symbols are defined in other .cpp files in the same dir.
/usr/llvm-gcc-4.2/bin/../libexec/gcc/i686-apple-darwin11/4.2.1/as -arch x86_64 -force_cpusubtype_ALL -o /var/folders/br/h6ln_j014ll56zwc8x6xjmk80000gn/T//ccSUmHal.o /var/folders/br/h6ln_j014ll56zwc8x6xjmk80000gn/T//ccn8ex81.s
/usr/llvm-gcc-4.2/bin/../libexec/gcc/i686-apple-darwin11/4.2.1/collect2 -dynamic -arch x86_64 -macosx_version_min 10.8.3 -weak_reference_mismatches non-weak -o Calcoli.o -lcrt1.10.6.o -L/usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/x86_64 -L/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/x86_64 -L/usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1 -L/usr/llvm-gcc-4.2/bin/../lib/gcc -L/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1 -L/usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/../../.. -L/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/../../.. /var/folders/br/h6ln_j014ll56zwc8x6xjmk80000gn/T//ccSUmHal.o -lstdc++ -lSystem -lgcc -lSystem
The compiler output ends with the "classic" undefined symbol issue. All emphasized text*emphasized text*emphasized text
Undefined symbols for architecture x86_64:
"typeinfo for TipoPuntoCalc", referenced from:
Calcoli::setPuntoS(GTGraphicObject*) in ccSUmHal.o
"typeinfo for TipoPali", referenced from:
Calcoli::setPaloS(GTGraphicObject*) in ccSUmHal.o
"typeinfo for TipoRett", referenced from:
Calcoli::setFondazioneS(GTGraphicObject*) in ccSUmHal.o
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [Calcoli.o] Error 1
This shouldn't be an architecture related issue, since specifing i386 as target has the same result (symbol(s) not found for architecture i386).
Thank you,
Evelina
Go to your target's "Build Phases" section and verify that all the files you need to compile and link are actually included in the proper sections.
It sounds as if the compiler is not being told to include some things you need.

Apple Mach-O Linker (Id) Error using gSOAP

I´m really stuck with this issue... and i hope you can help me out here.
I'm developing an iPad app for a company, that requires to use secured SOAP web services... not the perfect combination! i know, the thing is that taking a look around google, i found that the "best" thing to do was making a WS client using gSOAP and that´s what i did! now i have the client for one of those WS in C++.
When i try to call one of the methods of the WS, and build the app... this is what happens:
Ld /Users/me/Library/Developer/Xcode/DerivedData/App-akcairabnqiunvddtmwphaispprl/Build/Products/Debug-iphonesimulator/App.app/App normal i386
cd /Users/me/iOS/App
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.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 i386 -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk
-L/Users/me/Library/Developer/Xcode/DerivedData/App-akcairabnqiunvddtmwphaispprl/Build/Products/Debug-iphonesimulator
-L/Users/me/iOS/App -F/Users/me/Library/Developer/Xcode/DerivedData/App-akcairabnqiunvddtmwphaispprl/Build/Products/Debug-iphonesimulator
-F/Applications/Xcode.app/Contents/Developer/Library/Frameworks
-filelist /Users/me/Library/Developer/Xcode/DerivedData/App-akcairabnqiunvddtmwphaispprl/Build/Intermediates/App.build/Debug-iphonesimulator/App.build/Objects-normal/i386/App.LinkFileList
-mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED=50100
-framework SenTestingKit -framework Foundation -framework UIKit -framework QuartzCore -framework CoreGraphics -ldataSOAPlibDev
-o /Users/me/Library/Developer/Xcode/DerivedData/App-akcairabnqiunvddtmwphaispprl/Build/Products/Debug-iphonesimulator/App.app/App
ld: warning: ignoring file /Users/me/iOS/App/libdataSOAPlibDev.a,
file was built for archive which is not the architecture being linked (i386)
Undefined symbols for architecture i386:
'soap::soap()', referenced from:
-[ViewContratosController viewDidLoad] in ViewContratosController.o
'_soap_init_LIBRARY_VERSION_REQUIRED_20808', referenced from:
-[ViewContratosController viewDidLoad] in ViewContratosController.o
'soap_call_ns1__obtenerPais(soap*, char const*, char const*, ns2__paisFile*,
ns1__obtenerPaisResponse&)', referenced from:
-[ViewContratosController viewDidLoad] in ViewContratosController.o
'soap::~soap()', referenced from:
-[ViewContratosController viewDidLoad] in ViewContratosController.o
'ns2__paisFile::soap_default(soap*)', referenced from:
ns2__paisFile::ns2__paisFile() in ViewContratosController.o
'vtable for ns2__paisFile', referenced from:
ns2__paisFile::ns2__paisFile() in ViewContratosController.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The NOTE may tell the problem... but i don´t know how to solve it... any ideas?
Thanks!
The problem is probably that you took a library for iPAd (ARM architecture) and tried to build to the simulator (i386 architecture). Try building to the actual device instead.
The hint for me was:
ld: warning: ignoring file /Users/me/iOS/App/libdataSOAPlibDev.a, file
was built for archive which is not the architecture being linked
(i386)
OK! i solved it including (not importing) the headers and the nsmap generated by gSOAP in the .mm file where i´m trying to consume the WS...
#include "soapH.h"
#include "soapStub.h"
#include "soapdataServiceSoapBindingProxy.h"
#include "dataServiceSoapBinding.nsmap"
If you are going to make a static library out of a WS Client created by gSOAP, be REALLY careful with the "Build Phases" of the library Project... add carefully the headers and the compile sources!
After that... import to your iOS proyect the "lib.a" with the headers and the XMLs under the same folder! and call the WS doing something like this:
dataServiceSoapBinding service;
ns2__countryFile country;
struct ns1__getCountryResponse response;
country.idCountry = 11;
if(service.ns1__getCountry(&country, response) == SOAP_OK) {
NSLog(#"ok");
} else {
NSLog(#"ERROR");
}
I hope this may help anybody... because i had such a hard time figuring this out... and didn´t find much info about it!
:)

dylib on Snow Leopard "file is not of required architecture"

I have compiled opencv on snow leopard and it says it compiled correctly, however when I try to compile my sample program against it, I get output like:
g++ -o tm_scons template.o -L/opencv/opencv/build/lib -lcxcore -lcv -lcvaux -lhighgui -lml
ld: warning: in /opencv/opencv/build/lib/libcxcore.dylib, file is not of required architecture
ld: warning: in /opencv/opencv/build/lib/libcv.dylib, file is not of required architecture
ld: warning: in /opencv/opencv/build/lib/libcvaux.dylib, file is not of required architecture
ld: warning: in /opencv/opencv/build/lib/libhighgui.dylib, file is not of required architecture
ld: warning: in /opencv/opencv/build/lib/libml.dylib, file is not of required architecture
Is this likely a problem with my compilation of OpenCV or of my app that is using it?
Compiling correctly does not mean compiling for whatever architecture you're trying to compile now. Most likely the library is compiled as 32-bit and you're compiling as 64-bit or vice-versa.
Most likely your program is compiled 64-bit (the default behavior on SnowLeopard) and the library is compiled 32-bit. Try adding the -m32 or -arch i386 flag to the compiler when you build your program and see if the link works.
As it turns out the magic was using -m32 and switching to the /usr/bin/g++-4.0 compiler.
Ugh....