openGL object not found for architecture x86_64 - c++

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

Related

How to link against libGL on OSX using cmake?

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.

Xcode static library seems to change architecture on build

Here's a bit of background before I dive into the question. My ultimate goal is to compile the source of a c++ static library for the architectures arm64, armv7, armv7s, i386, and x86_64, and then package the libraries into a fat library so that I can use them during iOS development. This will enable me to use the simulator and a device with the same library.
Here's my issue. I'm trying to test the i386 version of the library, on it's own, using the iPhone 5 simulator. I compiled the static library for i386 as follows:
./configure --enable-utf8-only --disable-shared --host=i386-apple-darwin LDFLAGS="-L." CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" CXX="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++"
then
make CXXFLAGS="-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk" CCFLAGS="-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk"
This resulted in my static library, libtest.a. I then ran the follow to verify the libraries architecture
jamespc:Desktop $ lipo -info libtest.a
input file libtest.a is not a fat file
Non-fat file: libtest.a is architecture: i386
Everything seemed to look good so far. Next I added the library to my Xcode project and tried to build the project. When building the project I get the following warning and error.
ld: warning: ignoring file
/Users/cleandev/Library/Developer/Xcode/DerivedData/MyProject-hjtfdovfmdsubkejojqknkmqkzps/Build/Products/Debug-iphonesimulator/libtest.a,
file was built for archive which is not the architecture being linked (i386):
/Users/cleandev/Library/Developer/Xcode/DerivedData/MyProject-hjtfdovfmdsubkejojqknkmqkzps/Build/Products/Debug-iphonesimulator/libtest.a
Undefined symbols for architecture i386:
...
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Perplexed by error I ran lipo on my static lib again, this time using the path listed in the warning, in the derived data folder.
jamespc:Debug-iphonesimulator $ lipo -info libtest.a
input file libtest.a is not a fat file
Non-fat file: libtest.a is architecture: x86_64
I'm confused as to why the library appears to have a different architecture associated with it when I take a look at it in the derived data.
Is the way I'm compiling the static library wrong?
Is there something I might be doing wrong in my Xcode build settings?
Thank you for taking the time to read my question
I guess the framework was not compiled for the iOS Simulator's architecture, which is i386. Xcode only compiles a framework for the target architecture.
Please follow this tutorial: http://www.raywenderlich.com/65964/create-a-framework-for-ios
It may help.

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.

Building OsiriX on Mac OS X Lion

Ld build/Development/Decompress normal i386
cd /Users/icthealth/Desktop/dcmtk/osirix/osirix
setenv MACOSX_DEPLOYMENT_TARGET 10.7
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -L/Users/icthealth/Desktop/dcmtk/osirix/osirix/build/Development -LBinaries/LibTiff -L/Users/icthealth/Desktop/dcmtk/osirix/osirix/Binaries -L/Users/icthealth/Desktop/dcmtk/osirix/osirix/Binaries/Ming "-L/Users/icthealth/Desktop/dcmtk/osirix/osirix/Binaries/KDU SDK" -L/Users/icthealth/Desktop/dcmtk/osirix/osirix/Binaries/CharLS -L/Users/icthealth/Desktop/dcmtk/osirix/osirix/Binaries/VTKLibs -F/Users/icthealth/Desktop/dcmtk/osirix/osirix/build/Development -F/Users/icthealth/Desktop/dcmtk/osirix/osirix -filelist /Users/icthealth/Desktop/dcmtk/osirix/osirix/build/OsiriX_Lion.build/Development/Decompress.build/Objects-normal/i386/Decompress.LinkFileList -mmacosx-version-min=10.7 -framework Foundation -framework AppKit -framework Foundation -framework Cocoa -framework QuickTime -framework IOKit -lz "-lDCM StaticLibrary" -framework Accelerate -framework QTKit -framework WebKit -lPapyrusToolkit -lfreetypeOsiriX -lgifOsiriX -lmingOsiriX -lpng12OsiriX -lkdu_v64R -framework Quartz -lCharLS -lvtkzlib -o /Users/icthealth/Desktop/dcmtk/osirix/osirix/build/Development/Decompress
Undefined symbols for architecture i386:
".objc_class_name_DCMPix", referenced from:
pointer-to-literal-objc-class-name in Decompress.o
(maybe you meant: .objc_class_name_DCMPixelDataAttribute)
"_PapyrusLockFunction", referenced from:
_ExtractJPEG2000 in libPapyrusToolkit.a(PapyRead3.o)
_ExtractJPEGLS in libPapyrusToolkit.a(PapyRead3.o)
_ExtractJPEGlossy16 in libPapyrusToolkit.a(PapyJpeg16.o)
_ExtractJPEGlossy12 in libPapyrusToolkit.a(PapyJpeg12.o)
_ExtractJPEGlossy8 in libPapyrusToolkit.a(PapyJpeg8.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
While building after creating the Development Scheme for Mac OS X Lion 10.7, the above build errors are generated. Any clues how I can compile OsiriX on Mac OS X Lion 10.7?
Although this answer doesn't seem conclusive, I would like to mention what worked and what didn't. Before that, I am using Xcode version 4.3.2 and Mac OS X Lion 10.7.4. I downloaded the source code zip file for OsiriX.
Select "Unzip Binaries" and My Mac 32-bit as the target scheme first, and build and run. (This one was always successful).
Select "Osirix" and My Mac 32-bit as the next target scheme and, in this version of Xcode it says "Validate Project Settings", as it seemed to be necessary to update the compiler from llvmgcc42 to Apple LLVM, and change the Base SDK to latest Mac OS X (10.7) from the current 10.6 version.
When this change was performed, it threw up varieties of build errors, like the one on my original question, and Apple Mach-O linker error, CLang error, exited with code 1. and so on.
The successful compilation of Osirix in my opinion depends on keeping the old compiler and not updating to latest project settings.

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....