g_object_set linker error with glib from MacPorts - macos

I get a strange linker error when building a project (which uses GStreamer 1.0 and therefore depends on Glib 2.0) with cmake and linking against glib library. Glib is installed using macports, libglib-2.0.0.dylib is present in /opt/local/lib/. FindGLIB successfully finds its header files (compiling works) and also ${GLIB_LIBRARIES} provides the right path to the library.
The error message is
[100%] Linking CXX executable ../bin/presenter
Undefined symbols for architecture x86_64:
"_g_object_set", referenced from:
...
"_g_type_check_instance_cast", referenced from:
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
If I remove glib from the list completely it's also copmplaining about missing reference to g_print and g_printerr. Is it possible that the linking is done correctly but the functions are just missing for some reason inside the library?
How can I fix it?

Finally found my mistake. When using FindGLIB of the Webkit project, it by default searches only for the main glib library. It's components have to be passed in addition to be found:
find_package(GLIB COMPONENTS gobject REQUIRED)
would find glib itself and save it in ${GLIB_LIBRARIES} and also gobject and save it in ${GLIB_GOBJECT_LIBRARIES} so they can be used in target_link_libraries()
Reminder: Always read the comments in the file headers - they often contain useful information...
# Optionally, the COMPONENTS keyword can be passed to find_package()
# and Glib components can be looked for. Currently, the following
# components can be used, and they define the following variables if
# found:
#
# gio: GLIB_GIO_LIBRARIES
# gobject: GLIB_GOBJECT_LIBRARIES
# gmodule: GLIB_GMODULE_LIBRARIES
# gthread: GLIB_GTHREAD_LIBRARIES

Related

Duplicate symbols for architecture armv7 : soomla issue

I got this error after reimporting the soomla package.
How to solve this?
duplicate symbol _NewBase64Encode_soomla in:
/Users/Nikunj/Unity/2D/NoOneCanDoIt/Build/b2/Libraries/Plugins/iOS/Soomla/libSoomlaiOSCore.a(NSData-Base64.o)
/Users/Nikunj/Unity/2D/NoOneCanDoIt/Build/b2/Libraries/Plugins/iOS/SoomlaShared/libKeeva.a(NSData-Base64.o)
duplicate symbol _NewBase64Decode_soomla in:
/Users/Nikunj/Unity/2D/NoOneCanDoIt/Build/b2/Libraries/Plugins/iOS/Soomla/libSoomlaiOSCore.a(NSData-Base64.o)
/Users/Nikunj/Unity/2D/NoOneCanDoIt/Build/b2/Libraries/Plugins/iOS/SoomlaShared/libKeeva.a(NSData-Base64.o)
duplicate symbol _OBJC_CLASS_$_FBEncryptorAES in:
/Users/Nikunj/Unity/2D/NoOneCanDoIt/Build/b2/Libraries/Plugins/iOS/Soomla/libSoomlaiOSCore.a(FBEncryptorAES.o)
/Users/Nikunj/Unity/2D/NoOneCanDoIt/Build/b2/Libraries/Plugins/iOS/SoomlaShared/libKeeva.a(FBEncryptorAES.o)
duplicate symbol _OBJC_METACLASS_$_FBEncryptorAES in:
/Users/Nikunj/Unity/2D/NoOneCanDoIt/Build/b2/Libraries/Plugins/iOS/Soomla/libSoomlaiOSCore.a(FBEncryptorAES.o)
/Users/Nikunj/Unity/2D/NoOneCanDoIt/Build/b2/Libraries/Plugins/iOS/SoomlaShared/libKeeva.a(FBEncryptorAES.o)
ld: 4 duplicate symbols for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Showing first 200 warnings only
Unfortunately libKeeva and libSoomlaiOSCore contain the same functions and classes (symbols). You need to exclude one of these libraries or rebuilt one of them not using conflicting symbols (or make it depend on another library).
Another variant is to include one of the libraries to your project as source code.
UPD: it seems like libSoomlaiOSCore and libKeeva is simply two versions of Soomla, so you can just delete one of them.

Portable plugins with CMake

I am trying to find a portable way of generating modules (dlopen, dlsym, dlerror, dlclose) with CMake.
The whole source code of my attempt is located here.
Here is the CMake script:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(dlopen_example CXX)
ADD_EXECUTABLE(main main.cpp print_ref.cpp)
TARGET_LINK_LIBRARIES(main dl)
ADD_LIBRARY(module MODULE module.cpp)
IF(APPLE)
SET_TARGET_PROPERTIES(module PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
ENDIF(APPLE)
As you may remark, I have to add
-undefined dynamic_lookup
to the set of link flags on Mac OSX (clang compiler). Indeed, while there is no problem on Linux Ubuntu, I get an error message on Mac OSX if I do not add this flag and let CMake handle flags with the line
ADD_LIBRARY(module MODULE module.cpp)
The error message I get is the following:
Undefined symbols for architecture x86_64:
"print_ref()", referenced from:
_module in module.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am surprised that the MODULE option of ADD_LIBRARY does not handle such a flag.Is there a portable solution to this problem with CMake?

What does undefined symbols for architecture x86_64 mean?

I am trying to build eigen on my Mac Air with Lion. I downloaded eigen3 (from http://eigen.tuxfamily.org/index.php?title=Main_Page) and have successfully run make install. However, when I try to run make check, I get the following error.
[ 1%] Built target sparse_extra_2
Linking CXX executable openglsupport
ld: warning: ignoring file /System/Library/Frameworks//GLEW.framework/GLEW,
missing required architecture x86_64 in file
Undefined symbols for architecture x86_64:
"_glewExperimental", referenced from:
test_openglsupport() in openglsupport.cpp.o
"_glewInit", referenced from:
test_openglsupport() in openglsupport.cpp.o
"_glBegin", referenced from:
test_openglsupport() in openglsupport.cpp.o
I feel that this issue has to do with glew. I am now trying to install different versions of glew, but that doesn't seem to do anything.
Any advice on how to resolve the error? What does undefined symbols for architecture x86_64 mean anyway?
This probably means your installation of GLEW is incomplete. You can properly disable testing of OpenGL with cmake . -DEIGEN_TEST_NO_OPENGL=ON. Finally, note that Eigen is a header only library, so there is nothing to compile to use it.

Ignoring an undefined symbol in a dynamic library from Xcode

I have a symbol that is being referenced in an Xcode dynamic library target, but it is not defined there. I NEED this symbol to be undefined. This is because it will be compiled differently in each process that includes it (based upon some compile time defines).
The dynamic library target in Xcode that fails to link because it contains a reference to this symbol (which is not unexpected), but I know that the symbol will be available at run time. I will be compiling this function into each target that the common library is linked to.
I am trying to get the linker to mark this particular symbol for dynamic lookup at run time.
I have been able to get it to link if I specify "-undefined dynamic_lookup" as one of the "Other Linker Flags" in my Xcode project. The problem is that I don't want to go that far. I know that only 1 symbol is supposed to be undefined. I want all the rest of the symbols to generate errors if they are left as undefined (I want to avoid a run time missing symbol error basically).
I found a ld linker option that seems like it should do what I need (from ld man page):
-U symbol_name
Specified that it is ok for symbol_name to have no definition. With -two_levelnamespace, the resulting symbol will be marked dynamic_lookup which means dyld will search all loaded images.
However, I cannot seem to get it to work. Whenever I specify "-U symbolName" or "-UsymbolName" in the "Other Linker Flags" I am still greeted with this linker error:
Undefined symbols for architecture x86_64:
"_symbolName", referenced from: <various object files>
Am I using -U incorrectly perhaps? Is it not really the option I need, or is it just not working like it is supposed too?
Set -Wl,-undefined,dynamic_lookup to OTHER_LDFLAGS.
Link: Xcode clang link: Build Dynamic Framework (or dylib) not embed dependencies
Setting -Wl,-undefined,dynamic_lookup is dangerous, since it disables all undefined warning.
Use -Wl,-U,symbol_namein OTHER_LDFLAGS to disable warnings for a single symbol.
In Xcode:
Go to Project/Select Target
Click Build Settings
Search Other Linker Flags
Enter options

Unity project. Undefined symbols for architecture armv7

I make a build for iPhone for the first time and got a problem.
I already checked a lot of posts and didnt find answer.
When i make a build on device a get:
Undefined symbols for architecture armv7:
"RegisterAllStrippedInternalCalls()", referenced from:
RegisterAllInternalCalls() in libiPhone-lib.a(MonoICallRegistration.o)
"RegisterAllClasses()", referenced from:
InitializeEngineNoGraphics() in libiPhone-lib.a(SaveAndLoadHelper.o)
"RegisterMonoModules()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
On simulator ok.
libiPhone-lib.a added to link libraries.
Can somebody tell what it is? Please
Your unity version is not compatible, just download the latest version of unity which I believe is 4.3.1 and try recompiling. Here is the link if you need it. http://unity3d.com/unity/download/download-mac
The new version is compatible with armv7.
ok if anyone else is experiencing the same problem here's a way out:
those 3 methods mentioned are declared in the RegisterMonoModules.cpp in the Libraries folder, usually. so take that cpp file and add it to your target's Build Phases > Compile Sources
then if you have additional SDK's integrated that are not added to the 'Compile Sources' the new build will throw some other errors. just make sure to add the wrapper .mm files from the sdk's to your Compile Sources. Usually one .mm file per sdk. (e.g. for unity facebook sdk it's FbUnityInterface.mm file)
hope this helps

Resources