How to link against libGL on OSX using cmake? - opengl

I'm trying to compile camera_calibration on OSX 10.11 and after a few hurdles with a few X11 related dependencies I find myself still stuck with a few linking errors:
Undefined symbols for architecture x86_64:
"_glXChooseVisual", referenced from:
vis::OpenGLContextGLX::InitializeWindowless(vis::OpenGLContextImpl*) in opengl_context_glx.cc.o
"_glXCreateContext", referenced from:
vis::OpenGLContextGLX::InitializeWindowless(vis::OpenGLContextImpl*) in opengl_context_glx.cc.o
"_glXDestroyContext", referenced from:
vis::OpenGLContextGLX::Deinitialize() in opengl_context_glx.cc.o
"_glXGetCurrentContext", referenced from:
vis::IsOpenGLContextAvailable() in opengl.cc.o
vis::OpenGLContextGLX::AttachToCurrent() in opengl_context_glx.cc.o
"_glXGetCurrentDisplay", referenced from:
vis::OpenGLContextGLX::AttachToCurrent() in opengl_context_glx.cc.o
"_glXGetCurrentDrawable", referenced from:
vis::OpenGLContextGLX::AttachToCurrent() in opengl_context_glx.cc.o
"_glXMakeCurrent", referenced from:
vis::OpenGLContextGLX::MakeCurrent() in opengl_context_glx.cc.o
ld: symbol(s) not found for architecture x86_64
I found libGL.dylib has these symbols:
for lib in /usr/X11R6/lib/*.dylib;do nm -gU $lib | grep _glXChooseVisual;done
000000000000307f T _glXChooseVisual
000000000000307f T _glXChooseVisual
gp:src George$ for lib in /usr/X11R6/lib/*.dylib;do echo $lib && nm -gU $lib | grep _glXChooseVisual;done
/usr/X11R6/lib/libAppleWM.7.dylib
/usr/X11R6/lib/libAppleWM.dylib
/usr/X11R6/lib/libFS.6.dylib
/usr/X11R6/lib/libFS.dylib
/usr/X11R6/lib/libGL.1.dylib
000000000000307f T _glXChooseVisual
/usr/X11R6/lib/libGL.dylib
000000000000307f T _glXChooseVisual
However I can't seem to tweak CMakeLists.txt to take this into account.
I've tried adding:
set(X11R6_INCLUDE_DIRS "/usr/X11R6/include")
set(X11R6_LIBRARIES "/usr/X11R6/lib")
which I later use when calling target_include_directories and target_link_libraries for libvis, but doesn't seem to do the trick.
Hackily adding -lGL in target_link_libraries results in ld: library not found for -lGL
I've also looked at CMake's FindOpenGL reference and tried using find_package(OpenGL REQUIRED COMPONENTS OpenGL GLX) but didn't get very far:
CMake Error at /usr/local/Cellar/cmake/3.18.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
Could NOT find OpenGL (missing: GLX)
Any tips on correctly linking against GLX via CMake on OSX ?

On macOS do not(!) develop against X11 / GLX. They are not natively supported! The X11 server for macOS supports only indirect GLX with limited functionality. You will get only sub par performance. And CUDA (used by libvis) is not supported.
On macOS all OpenGL development should use the native OpenGL framework: https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_contexts/opengl_contexts.html
However take note that OpenGL has been declared deprecated by Apple.
In short: You'll at least have to modify your program to use the macOS OpenGL framework, or even bite the bullet and accept that macOS is not a well supported platform for your application.

Related

Boost undefined symbol for architecture arm64

I'm trying to build a project that contains code with boost 1.65.1 required.
I'm on a Mac OS M1 chipset (arm64)
I downloaded boost using homebrew
brew install boost
and the version 1.80.0 was correctly installed.
I complice using gcc g++ (and not clang)
I include the library in my cmake and all the includes are working fine and my IDE is able to find all the function references.
At some part of the code I'm using
boost::this_fiber::sleep_for function,
and at the compilation an error is raised by the linker
Undefined symbols for architecture arm64:
"_boost::fibers::context::wait_until(std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long long, std::ratio<1l, 1000000000l> > > const&)", referenced from:
_void boost::this_fiber::sleep_for<long long, std::ratio<1l, 1000000l> >(std::chrono::duration<long long, std::ratio<1l, 1000000l> > const&) in libTest.a
ld: symbol(s) not found for architecture arm64
in my case I find the boost package and linked all boost libraries.
I even tried by hand to add -lboost_fiber-mt or Boost::fiber and I always end up with the same error.
Do you have any idea why the symbol is undefined ? The same code works perfectly on a ubuntu x86_64.
I tried include the libraries by hand in the make and symbols is always undefined.
Probably not quite the answer you're looking for unfortunately, but I've had the same experience with a brew install, but have had success building the boost libraries myself, downloading from here and following installation instructions here. Hope this is helpful!

__glewX* Undefined Symbols in XQuartz Build

​I am trying to compile an X11 application on Mac OS X using XQuartz (i.e. XQuartz provides an X11 implementation, so the code should compile directly).
The X11 code, however, is sophisticated enough to require OpenGL extensions through GLEW. This almost works, but a few symbols remain undefined. Here's the relevant, cleaned-up output of the verbose link:
"/usr/bin/ld" [flags] -o [out] [lib-dirs] [obj-file] [CustomLib2 CustomLib1] -lX11.6 -lGLEW -lGLEW.1.10 -lc++ -lstdc++ -lSystem /usr/bin/../lib/clang/4.2/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"___glewXChooseFBConfig", referenced from: [place in CustomLib2]
"___glewXCreateContextAttribsARB", referenced from: [place in CustomLib2]
"___glewXSwapIntervalEXT", referenced from: [place in CustomLib2]
I checked the libraries, and they don't have any __glewX* symbols (though they have lots of __glew* symbols), despite this suggesting they should be there. I.e., these commands both come up empty:
nm /usr/lib/libGLEW.a | grep __glewX
nm /usr/lib/libGLEW.1.10.0.dylib | grep __glewX
My question: where are the __glewX* symbols located?
N.B. I am not using XCode or CMake. This is a simple makefile build.

openGL object not found for architecture x86_64

I am working on a project, using both opencv and openGL, compiling with Cmake on OSX. I get this error message:
_glTexImage2D", referenced from:
matToTexture(cv::Mat) in getimages.cpp.o
ld: symbol(s) not found for architecture x86_64
I guess I have to use openGL 64bit instead of 32bit, but I don't know how to specify this.
When compiling for MacOS X you must add the OpenGL framework. The compiler command line option is
-Framework OpenGL

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!
:)