Undefined references to symbols on Objective-C source compilation - objective-c

These days, I've been messing around with the Objective-C runtime, trying to find out how some things work. In one of my "experiments", I did the following: I got the following code which is in a file called test.m:
#import <objc/Object.h>
#interface MySuperClass: Object {
}
-(int) myMessage1;
#end
#interface MyClass: MySuperClass {
int myIvar;
}
-(void) myMessage2;
#end
#implementation MyClass
-(void) myMessage2 {
myIvar++;
}
#end
int main() {
MyClass *myObject;
myObject = [[MyClass alloc] init];
[myObject myMessage2];
return 0;
}
and tried to compile it with clang -fobjc-nonfragile-abi -fnext-runtime -o test test.m. As you can imagine, the compiler will generate a linking error message because I'm compiling an Objective-C file, but I'm not telling the linker to link it against an Objective-C runtime library (with the -lobjc option, for example). But I did that on purpose, to check out which objc runtime library symbols would be referenced and, thus, would be missing. And I got the following error message:
$ clang -fobjc-nonfragile-abi -fnext-runtime -o test test.m
/tmp/test-jEfgSA.o:(__DATA, __objc_data+0x0): undefined reference to `OBJC_METACLASS_$_Object'
/tmp/test-jEfgSA.o:(__DATA, __objc_data+0x8): undefined reference to `OBJC_METACLASS_$_MySuperClass'
/tmp/test-jEfgSA.o:(__DATA, __objc_data+0x10): undefined reference to `_objc_empty_cache'
/tmp/test-jEfgSA.o:(__DATA, __objc_data+0x18): undefined reference to `_objc_empty_vtable'
/tmp/test-jEfgSA.o:(__DATA, __objc_data+0x30): undefined reference to `OBJC_CLASS_$_MySuperClass'
/tmp/test-jEfgSA.o:(__DATA, __objc_data+0x38): undefined reference to `_objc_empty_cache'
/tmp/test-jEfgSA.o:(__DATA, __objc_data+0x40): undefined reference to `_objc_empty_vtable'
/tmp/test-jEfgSA.o:(__DATA, __objc_msgrefs, coalesced+0x0): undefined reference to `objc_msgSend_fixup'
/tmp/test-jEfgSA.o:(__DATA, __objc_msgrefs, coalesced+0x10): undefined reference to `objc_msgSend_fixup'
/tmp/test-jEfgSA.o:(__DATA, __objc_msgrefs, coalesced+0x20): undefined reference to `objc_msgSend_fixup'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
It's easy to understand why some of the listed symbols are undefined. objc_msgSend_fixup, for example, refers to a runtime library function. _objc_empty_cache and _objc_empty_vtable are both runtime library structs declared in http://opensource.apple.com/source/objc4/objc4-532/runtime/objc-abi.h. However, OBJC_METACLASS_$_MySuperClass and OBJC_CLASS_$_MySuperClass are structs that represent a class that has been declared in test.m, so that there is no reference in the Objective-C runtime library to these symbols. They should be defined in teste.o, but it seems they're not. So, why does this happen?
And one more thing: there is no broken reference to neither OBJC_METACLASS_$_MyClass nor OBJC_CLASS_$_MyClass. Therefore, there are broken references to Object and MySuperClass and both of them have subclasses in test.m, but there is no broken reference to MyClass, which has no subclass. So, why the linker seems to expect there to be references, in the runtime library, to the classes that have subclasses, but not to those that haven't any?

Good to experiment with these sorts of things. It will be helpful later when you get similar errors and need to debug.
A few points that stick out:
This isn't really about subclassing. You could get similar errors just by trying to instantiate an Object, for example.
The linker tries (in simplified terms) to match compiled code, and its associated symbol table, up with references in the code.
You don't have an implementation of MySuperClass, so no object code is generated, and no symbols exists that match your interface definition of MySuperClass. You can make this error go away by implementing MySuperClass.
MyClass is fine, because you have implemented MyClass in the file, so the linker can find a valid symbol to link to.

I found out that the OBJC_METACLASS_$_<my class name> symbols are defined in the object file only if there is an #implementation <my class name> statement. So, if I add, for example, the snippet:
#implementation MySuperClass
-(int) myMessage1 {
return 0;
}
#end
to test.m, the linker would generate the error message:
$ clang -fobjc-nonfragile-abi -fnext-runtime -o class_teste class_teste.m
/tmp/class_teste-gDWfF6.o:(__DATA, __objc_data+0x0): undefined reference to `OBJC_METACLASS_$_Object'
/tmp/class_teste-gDWfF6.o:(__DATA, __objc_data+0x8): undefined reference to `OBJC_METACLASS_$_Object'
/tmp/class_teste-gDWfF6.o:(__DATA, __objc_data+0x10): undefined reference to `_objc_empty_cache'
/tmp/class_teste-gDWfF6.o:(__DATA, __objc_data+0x18): undefined reference to `_objc_empty_vtable'
/tmp/class_teste-gDWfF6.o:(__DATA, __objc_data+0x30): undefined reference to `OBJC_CLASS_$_Object'
/tmp/class_teste-gDWfF6.o:(__DATA, __objc_data+0x38): undefined reference to `_objc_empty_cache'
/tmp/class_teste-gDWfF6.o:(__DATA, __objc_data+0x40): undefined reference to `_objc_empty_vtable'
/tmp/class_teste-gDWfF6.o:(__DATA, __objc_data+0x50): undefined reference to `OBJC_METACLASS_$_Object'
/tmp/class_teste-gDWfF6.o:(__DATA, __objc_data+0x60): undefined reference to `_objc_empty_cache'
/tmp/class_teste-gDWfF6.o:(__DATA, __objc_data+0x68): undefined reference to `_objc_empty_vtable'
/tmp/class_teste-gDWfF6.o:(__DATA, __objc_data+0x88): undefined reference to `_objc_empty_cache'
/tmp/class_teste-gDWfF6.o:(__DATA, __objc_data+0x90): undefined reference to `_objc_empty_vtable'
/tmp/class_teste-gDWfF6.o:(__DATA, __objc_msgrefs, coalesced+0x0): undefined reference to `objc_msgSend_fixup'
/tmp/class_teste-gDWfF6.o:(__DATA, __objc_msgrefs, coalesced+0x10): undefined reference to `objc_msgSend_fixup'
/tmp/class_teste-gDWfF6.o:(__DATA, __objc_msgrefs, coalesced+0x20): undefined reference to `objc_msgSend_fixup'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
which is pretty acceptable, since all these undefined symbols are part of the Objective-C runtime library. Since my first version of test.m was for testing purpose, I hadn't added an implementation to the MySuperClass class as I thought it wouldn't affect the object file's symbols table. So, the problem has nothing to do with subclassing.

Related

Unable to build frequensea

I'm trying to build the package frequensea, but I'm having errors.
I edited CMakeCache.txt to fill in the path for required libraries and I was expecting not to have more obstacles to build the software.
However, this is the output from make:
sdr#sdr:/home/sdr/frequensea/build$ make
Scanning dependencies of target lua
[ 2%] Linking C static library liblua.a
[ 75%] Built target lua
Scanning dependencies of target frequensea
[ 77%] Building CXX object CMakeFiles/frequensea.dir/src/main.cpp.o
[ 79%] Building C object CMakeFiles/frequensea.dir/src/nfile.c.o
[ 81%] Building C object CMakeFiles/frequensea.dir/src/ngl.c.o
[ 83%] Building C object CMakeFiles/frequensea.dir/src/nim.c.o
[ 85%] Building C object CMakeFiles/frequensea.dir/src/noise.c.o
[ 87%] Building C object CMakeFiles/frequensea.dir/src/nosc.c.o
[ 89%] Building C object CMakeFiles/frequensea.dir/src/nrf.c.o
[ 91%] Building C object CMakeFiles/frequensea.dir/src/nut.c.o
[ 93%] Building C object CMakeFiles/frequensea.dir/src/nwm.c.o
[ 95%] Building C object CMakeFiles/frequensea.dir/src/obj.c.o
[ 97%] Building C object CMakeFiles/frequensea.dir/src/vec.c.o
[100%] Linking CXX executable frequensea
externals/lua/liblua.a(loslib.c.o): In function `os_tmpname':
/home/sdr/sdr/frequensea/externals/lua/src/loslib.c:140: warning: the use of `tmpnam' is dangerous, better use `mkstemp'
CMakeFiles/frequensea.dir/src/ngl.c.o: In function `ngl_check_compile_error':
/home/sdr/frequensea/src/ngl.c:80: undefined reference to `__glewGetShaderiv'
/home/sdr/frequensea/src/ngl.c:83: undefined reference to `__glewGetShaderInfoLog'
CMakeFiles/frequensea.dir/src/ngl.c.o: In function `ngl_check_link_error':
/home/sdr/frequensea/src/ngl.c:92: undefined reference to `__glewGetProgramiv'
/home/sdr/frequensea/src/ngl.c:95: undefined reference to `__glewGetProgramInfoLog'
CMakeFiles/frequensea.dir/src/ngl.c.o: In function `ngl_shader_new':
/home/sdr/frequensea/src/ngl.c:102: undefined reference to `__glewCreateShader'
/home/sdr/frequensea/src/ngl.c:103: undefined reference to `__glewShaderSource'
/home/sdr/frequensea/src/ngl.c:104: undefined reference to `__glewCompileShader'
/home/sdr/frequensea/src/ngl.c:108: undefined reference to `__glewCreateShader'
/home/sdr/frequensea/src/ngl.c:109: undefined reference to `__glewShaderSource'
/home/sdr/frequensea/src/ngl.c:110: undefined reference to `__glewCompileShader'
/home/sdr/frequensea/src/ngl.c:114: undefined reference to `__glewCreateProgram'
/home/sdr/frequensea/src/ngl.c:115: undefined reference to `__glewAttachShader'
/home/sdr/frequensea/src/ngl.c:116: undefined reference to `__glewAttachShader'
/home/sdr/frequensea/src/ngl.c:119: undefined reference to `__glewTransformFeedbackVaryings'
/home/sdr/frequensea/src/ngl.c:120: undefined reference to `__glewLinkProgram'
/home/sdr/frequensea/src/ngl.c:129: undefined reference to `__glewGetUniformLocation'
/home/sdr/frequensea/src/ngl.c:130: undefined reference to `__glewGetUniformLocation'
/home/sdr/frequensea/src/ngl.c:131: undefined reference to `__glewGetUniformLocation'
CMakeFiles/frequensea.dir/src/ngl.c.o: In function `ngl_shader_uniform_set_float':
/home/sdr/frequensea/src/ngl.c:146: undefined reference to `__glewUseProgram'
/home/sdr/frequensea/src/ngl.c:147: undefined reference to `__glewGetUniformLocation'
/home/sdr/frequensea/src/ngl.c:149: undefined reference to `__glewUniform1f'
/home/sdr/frequensea/src/ngl.c:151: undefined reference to `__glewUseProgram'
CMakeFiles/frequensea.dir/src/ngl.c.o: In function `ngl_shader_free':
/home/sdr/frequensea/src/ngl.c:155: undefined reference to `__glewDeleteShader'
/home/sdr/frequensea/src/ngl.c:156: undefined reference to `__glewDeleteShader'
/home/sdr/frequensea/src/ngl.c:157: undefined reference to `__glewDeleteProgram'
CMakeFiles/frequensea.dir/src/ngl.c.o: In function `ngl_texture_new':
/home/sdr/frequensea/src/ngl.c:170: undefined reference to `__glewActiveTexture'
/home/sdr/frequensea/src/ngl.c:179: undefined reference to `__glewGetUniformLocation'
CMakeFiles/frequensea.dir/src/ngl.c.o: In function `ngl_texture_update':
/home/sdr/frequensea/src/ngl.c:219: undefined reference to `__glewActiveTexture'
CMakeFiles/frequensea.dir/src/ngl.c.o: In function `ngl_model_new':
/home/sdr/frequensea/src/ngl.c:258: undefined reference to `__glewGenBuffers'
/home/sdr/frequensea/src/ngl.c:259: undefined reference to `__glewBindBuffer'
/home/sdr/frequensea/src/ngl.c:260: undefined reference to `__glewBufferData'
/home/sdr/frequensea/src/ngl.c:267: undefined reference to `__glewGenBuffers'
/home/sdr/frequensea/src/ngl.c:268: undefined reference to `__glewBindBuffer'
/home/sdr/frequensea/src/ngl.c:269: undefined reference to `__glewBufferData'
/home/sdr/frequensea/src/ngl.c:276: undefined reference to `__glewGenBuffers'
/home/sdr/frequensea/src/ngl.c:277: undefined reference to `__glewBindBuffer'
/home/sdr/frequensea/src/ngl.c:278: undefined reference to `__glewBufferData'
/home/sdr/frequensea/src/ngl.c:284: undefined reference to `__glewGenVertexArrays'
/home/sdr/frequensea/src/ngl.c:285: undefined reference to `__glewBindVertexArray'
/home/sdr/frequensea/src/ngl.c:288: undefined reference to `__glewEnableVertexAttribArray'
/home/sdr/frequensea/src/ngl.c:289: undefined reference to `__glewBindBuffer'
/home/sdr/frequensea/src/ngl.c:290: undefined reference to `__glewVertexAttribPointer'
/home/sdr/frequensea/src/ngl.c:295: undefined reference to `__glewEnableVertexAttribArray'
/home/sdr/frequensea/src/ngl.c:296: undefined reference to `__glewBindBuffer'
/home/sdr/frequensea/src/ngl.c:297: undefined reference to `__glewVertexAttribPointer'
/home/sdr/frequensea/src/ngl.c:302: undefined reference to `__glewEnableVertexAttribArray'
/home/sdr/frequensea/src/ngl.c:303: undefined reference to `__glewBindBuffer'
/home/sdr/frequensea/src/ngl.c:304: undefined reference to `__glewVertexAttribPointer'
CMakeFiles/frequensea.dir/src/ngl.c.o: In function `ngl_model_load_obj':
/home/sdr/frequensea/src/ngl.c:467: undefined reference to `__glewGenBuffers'
/home/sdr/frequensea/src/ngl.c:468: undefined reference to `__glewBindBuffer'
/home/sdr/frequensea/src/ngl.c:469: undefined reference to `__glewBufferData'
/home/sdr/frequensea/src/ngl.c:472: undefined reference to `__glewGenBuffers'
/home/sdr/frequensea/src/ngl.c:473: undefined reference to `__glewBindBuffer'
/home/sdr/frequensea/src/ngl.c:474: undefined reference to `__glewBufferData'
/home/sdr/frequensea/src/ngl.c:479: undefined reference to `__glewGenVertexArrays'
/home/sdr/frequensea/src/ngl.c:480: undefined reference to `__glewBindVertexArray'
/home/sdr/frequensea/src/ngl.c:481: undefined reference to `__glewEnableVertexAttribArray'
/home/sdr/frequensea/src/ngl.c:482: undefined reference to `__glewBindBuffer'
/home/sdr/frequensea/src/ngl.c:483: undefined reference to `__glewVertexAttribPointer'
/home/sdr/frequensea/src/ngl.c:484: undefined reference to `__glewEnableVertexAttribArray'
/home/sdr/frequensea/src/ngl.c:485: undefined reference to `__glewBindBuffer'
/home/sdr/frequensea/src/ngl.c:486: undefined reference to `__glewVertexAttribPointer'
CMakeFiles/frequensea.dir/src/ngl.c.o: In function `ngl_model_free':
/home/sdr/frequensea/src/ngl.c:498: undefined reference to `__glewDeleteBuffers'
/home/sdr/frequensea/src/ngl.c:499: undefined reference to `__glewDeleteBuffers'
/home/sdr/frequensea/src/ngl.c:500: undefined reference to `__glewDeleteBuffers'
/home/sdr/frequensea/src/ngl.c:501: undefined reference to `__glewDeleteVertexArrays'
CMakeFiles/frequensea.dir/src/ngl.c.o: In function `ngl_skybox_new':
/home/sdr/frequensea/src/ngl.c:620: undefined reference to `__glewGenBuffers'
/home/sdr/frequensea/src/ngl.c:621: undefined reference to `__glewBindBuffer'
/home/sdr/frequensea/src/ngl.c:622: undefined reference to `__glewBufferData'
/home/sdr/frequensea/src/ngl.c:624: undefined reference to `__glewGenVertexArrays'
/home/sdr/frequensea/src/ngl.c:625: undefined reference to `__glewBindVertexArray'
/home/sdr/frequensea/src/ngl.c:626: undefined reference to `__glewEnableVertexAttribArray'
/home/sdr/frequensea/src/ngl.c:627: undefined reference to `__glewBindBuffer'
/home/sdr/frequensea/src/ngl.c:628: undefined reference to `__glewVertexAttribPointer'
/home/sdr/frequensea/src/ngl.c:630: undefined reference to `__glewActiveTexture'
CMakeFiles/frequensea.dir/src/ngl.c.o: In function `ngl_skybox_draw':
/home/sdr/frequensea/src/ngl.c:652: undefined reference to `__glewUseProgram'
/home/sdr/frequensea/src/ngl.c:654: undefined reference to `__glewUniformMatrix4fv'
/home/sdr/frequensea/src/ngl.c:656: undefined reference to `__glewUniformMatrix4fv'
/home/sdr/frequensea/src/ngl.c:658: undefined reference to `__glewActiveTexture'
/home/sdr/frequensea/src/ngl.c:662: undefined reference to `__glewBindVertexArray'
CMakeFiles/frequensea.dir/src/ngl.c.o: In function `ngl_skybox_free':
/home/sdr/frequensea/src/ngl.c:671: undefined reference to `__glewDeleteBuffers'
/home/sdr/frequensea/src/ngl.c:672: undefined reference to `__glewDeleteVertexArrays'
CMakeFiles/frequensea.dir/src/ngl.c.o: In function `_ngl_draw_model':
/home/sdr/frequensea/src/ngl.c:689: undefined reference to `__glewUseProgram'
/home/sdr/frequensea/src/ngl.c:691: undefined reference to `__glewUniform1f'
/home/sdr/frequensea/src/ngl.c:693: undefined reference to `__glewUniformMatrix4fv'
/home/sdr/frequensea/src/ngl.c:695: undefined reference to `__glewUniformMatrix4fv'
/home/sdr/frequensea/src/ngl.c:698: undefined reference to `__glewBindVertexArray'
/home/sdr/frequensea/src/ngl.c:701: undefined reference to `__glewBeginTransformFeedback'
/home/sdr/frequensea/src/ngl.c:707: undefined reference to `__glewEndTransformFeedback'
/home/sdr/frequensea/src/ngl.c:711: undefined reference to `__glewBindVertexArray'
/home/sdr/frequensea/src/ngl.c:713: undefined reference to `__glewUseProgram'
CMakeFiles/frequensea.dir/src/ngl.c.o: In function `ngl_capture_model':
/home/sdr/frequensea/src/ngl.c:723: undefined reference to `__glewGenTransformFeedbacks'
/home/sdr/frequensea/src/ngl.c:726: undefined reference to `__glewGenBuffers'
/home/sdr/frequensea/src/ngl.c:728: undefined reference to `__glewBindTransformFeedback'
/home/sdr/frequensea/src/ngl.c:730: undefined reference to `__glewBindBuffer'
/home/sdr/frequensea/src/ngl.c:733: undefined reference to `__glewBufferData'
/home/sdr/frequensea/src/ngl.c:735: undefined reference to `__glewBindBufferBase'
/home/sdr/frequensea/src/ngl.c:743: undefined reference to `__glewGetBufferSubData'
/home/sdr/frequensea/src/ngl.c:748: undefined reference to `__glewDeleteBuffers'
/home/sdr/frequensea/src/ngl.c:750: undefined reference to `__glewDeleteTransformFeedbacks'
CMakeFiles/frequensea.dir/src/ngl.c.o: In function `ngl_font_new':
/home/sdr/frequensea/src/ngl.c:805: undefined reference to `__glewUseProgram'
/home/sdr/frequensea/src/ngl.c:807: undefined reference to `__glewGetUniformLocation'
/home/sdr/frequensea/src/ngl.c:809: undefined reference to `__glewGetUniformLocation'
/home/sdr/frequensea/src/ngl.c:811: undefined reference to `__glewUseProgram'
/home/sdr/frequensea/src/ngl.c:834: undefined reference to `__glewActiveTexture'
CMakeFiles/frequensea.dir/src/ngl.c.o: In function `ngl_font_draw':
/home/sdr/frequensea/src/ngl.c:903: undefined reference to `__glewUseProgram'
/home/sdr/frequensea/src/ngl.c:905: undefined reference to `__glewUniform2f'
/home/sdr/frequensea/src/ngl.c:907: undefined reference to `__glewUniform1f'
/home/sdr/frequensea/src/ngl.c:909: undefined reference to `__glewActiveTexture'
/home/sdr/frequensea/src/ngl.c:913: undefined reference to `__glewBindVertexArray'
/home/sdr/frequensea/src/ngl.c:918: undefined reference to `__glewBindVertexArray'
/home/sdr/frequensea/src/ngl.c:920: undefined reference to `__glewUseProgram'
collect2: error: ld returned 1 exit status
CMakeFiles/frequensea.dir/build.make:365: recipe for target 'frequensea' failed
make[2]: *** [frequensea] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/frequensea.dir/all' failed
make[1]: *** [CMakeFiles/frequensea.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Weak Link My Own Objective-C Class

Is it possible to weak link my own objective-c classes?
I have seen that I can weak link a function or a variable…
extern int MyFunction() __attribute__((weak_import));
extern int MyVariable __attribute__((weak_import));
I would like to have something like this…
if ([MyUploadManager class]) {
self.uploadButton.hidden = NO;
}
… and be able to compile even if UploadManager.m is not included in the project.
To weak link a class e.g. MyUploadManager in your own executable:
To keep the linker happy, add this to Other Linker Flags in the project:
-Wl,-U,_OBJC_CLASS_$_MyUploadManager
This allows the class symbol to be undefined even if it is not built into your executable. It will be considered for dynamic lookup instead, effectively the same as a dynamic library symbol.
To keep the runtime happy, add this to your class header:
__attribute__((weak_import)) #interface MyUploadManager
When the dynamic linker runs, it substitutes a nil for the class symbol rather than crashing.
Now you can run this without either linker or runtime errors:
if ([MyUploadManager class]) {
self.uploadButton.hidden = NO;
}
Note: As of Xcode 7, the -U linker options conflicts with BitCode, so you may not be able to use this technique for future projects.
You can use the NSClassFromString function:
Class MyUploadManager = NSClassFromString(#"MyUploadManager");
if (MyUploadManager) {
self.uploadButton.hidden = NO;
}
NSClassFromString returns nil if the class cannot be found.
To weak link a class it can be included in a framework. The compiler can be told to weak link all symbols in a framework using the Other Linker Flag build setting.
-weak_framework <framework_name>
This enables MyModule.framework to weak link against Uploader.framework whilst it is being built. If someone using MyModule.framework does not links against Uploader.framework then, in the example above, the button will not be displayed.
Frameworks and Weak Linking

undefined reference to `boost::this_thread:

I am trying to build to Doge coin headless wallet (similar to bitcoind) it seems to be Boost causing the error but I have no idea on how to fix it.
(Ubuntu 12.04)
When I execute "make -f makefile.unix USE_UPNP=-" I get this error:
/bin/sh ../share/genbuild.sh obj/build.h
g++ -O2 -pthread -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -g -DUSE_IPV6 -DBOOST_SPIRIT_THREADSAFE -I/root/dogecoin/src -I/root/dogecoin/src/obj -DHAVE_BUILD_INFO -fno-stack-protector -fstack-protector-all -Wstack-protector -D_FORTIFY_SOURCE=2 -o dogecoind obj/version.o obj/checkpoints.o obj/netbase.o obj/addrman.o obj/crypter.o obj/key.o obj/db.o obj/init.o obj/irc.o obj/keystore.o obj/main.o obj/net.o obj/protocol.o obj/bitcoinrpc.o obj/rpcdump.o obj/rpcnet.o obj/rpcrawtransaction.o obj/script.o obj/scrypt.o obj/sync.o obj/util.o obj/wallet.o obj/walletdb.o obj/noui.o -Wl,-z,relro -Wl,-z,now -Wl,-Bdynamic -l boost_system -l boost_filesystem -l boost_program_options -l boost_thread -l db_cxx -l ssl -l crypto -Wl,-Bdynamic -l z -l dl -l pthread
obj/db.o: In function `CAddrDB::Write(CAddrMan const&)':
/root/dogecoin/src/db.cpp:764: undefined reference to `RenameOver(boost::filesystem3::path, boost::filesystem3::path)'
obj/init.o: In function `AppInit2()':
/root/dogecoin/src/init.cpp:450: undefined reference to `CreatePidFile(boost::filesystem3::path const&, int)'
obj/main.o: In function `operator/':
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
obj/main.o: In function `sleep':
/usr/local/include/boost/thread/pthread/thread_data.hpp:249: undefined reference to `boost::this_thread::hiden::sleep_until(timespec const&)'
obj/main.o: In function `space':
/usr/local/include/boost/filesystem/operations.hpp:520: undefined reference to `boost::filesystem::detail::space(boost::filesystem::path const&, boost::system::error_code*)'
obj/main.o: In function `sleep':
/usr/local/include/boost/thread/pthread/thread_data.hpp:249: undefined reference to `boost::this_thread::hiden::sleep_until(timespec const&)'
obj/main.o: In function `boost::thread::start_thread()':
/usr/local/include/boost/thread/detail/thread.hpp:180: undefined reference to `boost::thread::start_thread_noexcept()'
obj/bitcoinrpc.o: In function `sleep':
/usr/local/include/boost/thread/pthread/thread_data.hpp:249: undefined reference to `boost::this_thread::hiden::sleep_until(timespec const&)'
obj/bitcoinrpc.o: In function `boost::filesystem::path::has_root_directory() const':
/usr/local/include/boost/filesystem/path.hpp:444: undefined reference to `boost::filesystem::path::root_directory() const'
obj/bitcoinrpc.o: In function `operator/':
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
obj/bitcoinrpc.o: In function `exists':
/usr/local/include/boost/filesystem/operations.hpp:289: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
obj/bitcoinrpc.o: In function `boost::filesystem::path::has_root_directory() const':
/usr/local/include/boost/filesystem/path.hpp:444: undefined reference to `boost::filesystem::path::root_directory() const'
obj/bitcoinrpc.o: In function `operator/':
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
obj/bitcoinrpc.o: In function `exists':
/usr/local/include/boost/filesystem/operations.hpp:289: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
obj/bitcoinrpc.o: In function `call_once<void (*)()>':
/usr/local/include/boost/thread/pthread/once_atomic.hpp:145: undefined reference to `boost::thread_detail::enter_once_region(boost::once_flag&)'
/usr/local/include/boost/thread/pthread/once_atomic.hpp:157: undefined reference to `boost::thread_detail::commit_once_region(boost::once_flag&)'
/usr/local/include/boost/thread/pthread/once_atomic.hpp:153: undefined reference to `boost::thread_detail::rollback_once_region(boost::once_flag&)'
/usr/local/include/boost/thread/pthread/once_atomic.hpp:145: undefined reference to `boost::thread_detail::enter_once_region(boost::once_flag&)'
/usr/local/include/boost/thread/pthread/once_atomic.hpp:157: undefined reference to `boost::thread_detail::commit_once_region(boost::once_flag&)'
/usr/local/include/boost/thread/pthread/once_atomic.hpp:153: undefined reference to `boost::thread_detail::rollback_once_region(boost::once_flag&)'
obj/util.o: In function `operator/':
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
obj/util.o: In function `path<char*>':
/usr/local/include/boost/filesystem/path.hpp:139: undefined reference to `boost::filesystem::path::codecvt()'
obj/util.o: In function `system_complete':
/usr/local/include/boost/filesystem/operations.hpp:531: undefined reference to `boost::filesystem::detail::system_complete(boost::filesystem::path const&, boost::system::error_code*)'
obj/util.o: In function `is_directory':
/usr/local/include/boost/filesystem/operations.hpp:294: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
obj/util.o: In function `create_directory':
/usr/local/include/boost/filesystem/operations.hpp:405: undefined reference to `boost::filesystem::detail::create_directory(boost::filesystem::path const&, boost::system::error_code*)'
obj/util.o: In function `GetDataDir(bool)':
/root/dogecoin/src/util.cpp:1029: undefined reference to `boost::filesystem::path::operator/=(char const*)'
obj/util.o: In function `operator/':
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
obj/util.o: In function `boost::filesystem::path::has_root_directory() const':
/usr/local/include/boost/filesystem/path.hpp:444: undefined reference to `boost::filesystem::path::root_directory() const'
obj/util.o: In function `operator/':
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
obj/util.o: In function `boost::filesystem::path::has_root_directory() const':
/usr/local/include/boost/filesystem/path.hpp:444: undefined reference to `boost::filesystem::path::root_directory() const'
obj/util.o: In function `operator/':
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
obj/walletdb.o: In function `sleep':
/usr/local/include/boost/thread/pthread/thread_data.hpp:249: undefined reference to `boost::this_thread::hiden::sleep_until(timespec const&)'
obj/walletdb.o: In function `operator/':
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
obj/walletdb.o: In function `is_directory':
/usr/local/include/boost/filesystem/operations.hpp:294: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
obj/walletdb.o: In function `copy_file':
/usr/local/include/boost/filesystem/operations.hpp:381: undefined reference to `boost::filesystem::detail::copy_file(boost::filesystem::path const&, boost::filesystem::path const&, boost::filesystem::copy_option::enum_type, boost::system::error_code*)'
obj/walletdb.o: In function `sleep':
/usr/local/include/boost/thread/pthread/thread_data.hpp:249: undefined reference to `boost::this_thread::hiden::sleep_until(timespec const&)'
obj/walletdb.o: In function `operator/=<std::basic_string<char> >':
/usr/local/include/boost/filesystem/path.hpp:302: undefined reference to `boost::filesystem::path::codecvt()'
obj/walletdb.o: In function `boost::filesystem::path& boost::filesystem::path::append<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::codecvt<wchar_t, char, __mbstate_t> const&)':
/usr/local/include/boost/filesystem/path.hpp:707: undefined reference to `boost::filesystem::path::m_append_separator_if_needed()'
/usr/local/include/boost/filesystem/path.hpp:710: undefined reference to `boost::filesystem::path::m_erase_redundant_separator(unsigned long)'
collect2: ld returned 1 exit status
make: *** [dogecoind] Error 1
You need to link against those boost libraries, i.e. add -lboost_thread -lboost_filesystem -lboost_system to your linker command lines.
See Link Your Program to a Boost Library for more details.
I was having the same problem, using boost 1.55.0.
I used nm on the boost libraries and none contained any symbol containing filesystem3
I am assuming that boost 1.55.0 removed filesystem3, possibly putting it into header only template but that's just a guess. I was linking the mongodbclient.a and I didn't want to recompile mongo from source (lots of setup required for that)
Moving to boost 1.49.0 fixed the problem. Those libraries had filesystem3 in them.
I had the same problems using boost 1.62.
However, in my case, as I have installed several boost versions on my Ubuntu 16.04, pointing the libraries and the include directory to the correct folders did help.
I made symbolic links for the include folder and the library folder (automatically done by boost installation):
/usr/include/boost -> /usr/local/boost_1_62_0/boost
and
/usr/local/lib/libboost_thread.so -> libboost_thread.so.1.62.0
If you are sure your linker is given the -lboost_... flags (see Maxim Egorushkin's answer) but you are still having the linker errors, there are a few other things to check:
Ensure you are linking against the correct version of boost
If you are using or have had multiple versions of boost on your system, it is possible there is a version discrepancy between the headers you are building against and the libraries you are attempting to link against. You will want to check the version that your libboost_*.so symlinks are linking to by running ls -l your_lib_path/lib/libboost_*.so. If these symlinks aren't pointing to the version of boost you want, you can modify the links.
You may also want to install boost in a unique location separate from your other libraries to ensure version consistency. If you do this, make sure to put the new path first in your LD_LIBRARY_PATH along with giving GCC the new -I include path flag (also should be first).
Check your pre-processor definitions
Especially if you are using a custom-built version of boost, you will want to ensure you are using the correct pre-processor definitions (-D flag) when trying to build and link against the libraries. As an example, in the header boost/thread/pthread/header_data.hpp:
#ifdef BOOST_THREAD_USES_CHRONO
#ifdef BOOST_THREAD_SLEEP_FOR_IS_STEADY
inline
void BOOST_SYMBOL_VISIBLE sleep_for(const chrono::nanoseconds& ns)
{
return boost::this_thread::hiden::sleep_for(boost::detail::to_timespec(ns));
}
#endif
#endif // BOOST_THREAD_USES_CHRONO
If the libraries were built without BOOST_THREAD_USES_CHRONO, the function void BOOST_SYMBOL_VISIBLE sleep_for(const chrono::nanoseconds& ns) will not be in the shared object library. If you were to build against this boost library with the BOOST_THREAD_USES_CHRONO definition, you may end up getting a linker error.

Why is my cmake file not working while usual g++ code works perfectly

I am using tesseract-ocr and leptonica library in my small project.
My "CMakeLists.txt" file looks like following: (I have necessary header files in 'include' folder)
cmake_minimum_required(VERSION 2.8.7)
project(OCR)
include_directories(include)
find_library(LEPT liblept)
find_library(TESS libtesseract)
set(LIBS ${LEPT} ${TESS})
add_executable(getText ocr.cpp)
target_link_libraries(getText ${LIBS})
But when I run this and then run make, my program does not get compiled
However, when I do this, it gets perfectly compiled
$ g++ ocr.cpp -o getText -I/usr/include/leptonica
-I/usr/local/include/tesseract -llept -ltesseract
But I need to make first approach succesful. Please help.
I have
#include "basapi.h"
#include "allheaders.h"
,by the way, in my code.
This is fine:
$ cmake .
/usr/local/lib/liblept.a/usr/local/lib/libtesseract.a
-- Configuring done
-- Generating done
-- Build files have been written to: /home/utkrist/OCR
But this is not (gives some leptonica and tesseract-ocr related errors)
$ make
Linking CXX executable getText
/usr/local/lib/libtesseract.a(imagefind.o): In function `tesseract::ImageFind::FindImages(Pix*)':
/home/utkrist/Downloads/tesseract-ocr/textord/imagefind.cpp:78: undefined reference to `pixGenHalftoneMask'
/usr/local/lib/libtesseract.a(tabfind.o): In function `tesseract::TabFind::Deskew(tesseract::TabVector_LIST*, BLOBNBOX_LIST*, TO_BLOCK*, FCOORD*, FCOORD*)':
/home/utkrist/Downloads/tesseract-ocr/textord/tabfind.cpp:1286: undefined reference to `pixRotate'
/usr/local/lib/libtesseract.a(svutil.o): In function `SVSemaphore':
/home/utkrist/Downloads/tesseract-ocr/viewer/svutil.cpp:129: undefined reference to `sem_init'
/usr/local/lib/libtesseract.a(svutil.o): In function `SVSemaphore::Signal()':
/home/utkrist/Downloads/tesseract-ocr/viewer/svutil.cpp:137: undefined reference to `sem_post'
/usr/local/lib/libtesseract.a(svutil.o): In function `SVSemaphore::Wait()':
/home/utkrist/Downloads/tesseract-ocr/viewer/svutil.cpp:145: undefined reference to `sem_wait'
/usr/local/lib/libtesseract.a(svutil.o): In function `SVSync::StartThread(void* (*)(void*), void*)':
/home/utkrist/Downloads/tesseract-ocr/viewer/svutil.cpp:188: undefined reference to `pthread_create'
/usr/local/lib/liblept.a(tiffio.o): In function `pixWriteToTiffStream':
/home/utkrist/leptonica-1.69/src/tiffio.c:646: undefined reference to `TIFFSetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:647: undefined reference to `TIFFSetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:648: undefined reference to `TIFFSetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:650: undefined reference to `TIFFSetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:651: undefined reference to `TIFFSetField'
/usr/local/lib/liblept.a(tiffio.o):/home/utkrist/leptonica-1.69/src/tiffio.c:652: more undefined references to `TIFFSetField' follow
/usr/local/lib/liblept.a(tiffio.o): In function `pixWriteToTiffStream':
/home/utkrist/leptonica-1.69/src/tiffio.c:723: undefined reference to `TIFFScanlineSize'
/home/utkrist/leptonica-1.69/src/tiffio.c:732: undefined reference to `TIFFSetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:742: undefined reference to `TIFFWriteScanline'
/home/utkrist/leptonica-1.69/src/tiffio.c:688: undefined reference to `TIFFSetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:689: undefined reference to `TIFFSetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:690: undefined reference to `TIFFSetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:691: undefined reference to `TIFFSetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:695: undefined reference to `TIFFSetField'
/usr/local/lib/liblept.a(tiffio.o):/home/utkrist/leptonica-1.69/src/tiffio.c:696: more undefined references to `TIFFSetField' follow
/usr/local/lib/liblept.a(tiffio.o): In function `pixWriteToTiffStream':
/home/utkrist/leptonica-1.69/src/tiffio.c:763: undefined reference to `TIFFWriteScanline'
/usr/local/lib/liblept.a(tiffio.o): In function `writeCustomTiffTags':
/home/utkrist/leptonica-1.69/src/tiffio.c:838: undefined reference to `TIFFSetField'
/usr/local/lib/liblept.a(tiffio.o): In function `pixWriteToTiffStream':
/home/utkrist/leptonica-1.69/src/tiffio.c:658: undefined reference to `TIFFSetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:750: undefined reference to `TIFFWriteScanline'
/home/utkrist/leptonica-1.69/src/tiffio.c:703: undefined reference to `TIFFSetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:713: undefined reference to `TIFFSetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:705: undefined reference to `TIFFSetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:707: undefined reference to `TIFFSetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:709: undefined reference to `TIFFSetField'
/usr/local/lib/liblept.a(tiffio.o):/home/utkrist/leptonica-1.69/src/tiffio.c:666: more undefined references to `TIFFSetField' follow
/usr/local/lib/liblept.a(tiffio.o): In function `getTiffStreamResolution':
/home/utkrist/leptonica-1.69/src/tiffio.c:1188: undefined reference to `TIFFGetFieldDefaulted'
/home/utkrist/leptonica-1.69/src/tiffio.c:1189: undefined reference to `TIFFGetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:1190: undefined reference to `TIFFGetField'
/usr/local/lib/liblept.a(tiffio.o): In function `tiffReadHeaderTiff':
/home/utkrist/leptonica-1.69/src/tiffio.c:1429: undefined reference to `TIFFGetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:1431: undefined reference to `TIFFGetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:1433: undefined reference to `TIFFGetFieldDefaulted'
/home/utkrist/leptonica-1.69/src/tiffio.c:1435: undefined reference to `TIFFGetFieldDefaulted'
/home/utkrist/leptonica-1.69/src/tiffio.c:1446: undefined reference to `TIFFGetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:1451: undefined reference to `TIFFGetFieldDefaulted'
/usr/local/lib/liblept.a(tiffio.o): In function `pixReadFromTiffStream':
/home/utkrist/leptonica-1.69/src/tiffio.c:287: undefined reference to `TIFFGetFieldDefaulted'
/home/utkrist/leptonica-1.69/src/tiffio.c:288: undefined reference to `TIFFGetFieldDefaulted'
/home/utkrist/leptonica-1.69/src/tiffio.c:299: undefined reference to `TIFFGetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:300: undefined reference to `TIFFGetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:301: undefined reference to `TIFFScanlineSize'
/home/utkrist/leptonica-1.69/src/tiffio.c:334: undefined reference to `TIFFReadRGBAImageOriented'
/home/utkrist/leptonica-1.69/src/tiffio.c:362: undefined reference to `TIFFGetFieldDefaulted'
/home/utkrist/leptonica-1.69/src/tiffio.c:366: undefined reference to `TIFFGetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:399: undefined reference to `TIFFGetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:315: undefined reference to `TIFFReadScanline'
/home/utkrist/leptonica-1.69/src/tiffio.c:382: undefined reference to `TIFFGetField'
/usr/local/lib/liblept.a(tiffio.o): In function `openTiff':
/home/utkrist/leptonica-1.69/src/tiffio.c:1721: undefined reference to `TIFFOpen'
/usr/local/lib/liblept.a(tiffio.o): In function `fopenTiff':
/home/utkrist/leptonica-1.69/src/tiffio.c:1689: undefined reference to `TIFFFdOpen'
/usr/local/lib/liblept.a(tiffio.o): In function `fopenTiffMemstream':
/home/utkrist/leptonica-1.69/src/tiffio.c:1983: undefined reference to `TIFFClientOpen'
/usr/local/lib/liblept.a(tiffio.o): In function `pixReadStreamTiff':
/home/utkrist/leptonica-1.69/src/tiffio.c:231: undefined reference to `TIFFReadDirectory'
/home/utkrist/leptonica-1.69/src/tiffio.c:237: undefined reference to `TIFFCleanup'
/home/utkrist/leptonica-1.69/src/tiffio.c:241: undefined reference to `TIFFCleanup'
/home/utkrist/leptonica-1.69/src/tiffio.c:226: undefined reference to `TIFFCleanup'
/usr/local/lib/liblept.a(tiffio.o): In function `pixWriteTiffCustom':
/home/utkrist/leptonica-1.69/src/tiffio.c:516: undefined reference to `TIFFClose'
/usr/local/lib/liblept.a(tiffio.o): In function `pixWriteStreamTiff':
/home/utkrist/leptonica-1.69/src/tiffio.c:576: undefined reference to `TIFFCleanup'
/home/utkrist/leptonica-1.69/src/tiffio.c:572: undefined reference to `TIFFCleanup'
/usr/local/lib/liblept.a(tiffio.o): In function `fprintTiffInfo':
/home/utkrist/leptonica-1.69/src/tiffio.c:1078: undefined reference to `TIFFPrintDirectory'
/home/utkrist/leptonica-1.69/src/tiffio.c:1079: undefined reference to `TIFFClose'
/usr/local/lib/liblept.a(tiffio.o): In function `tiffGetCount':
/home/utkrist/leptonica-1.69/src/tiffio.c:1114: undefined reference to `TIFFReadDirectory'
/home/utkrist/leptonica-1.69/src/tiffio.c:1118: undefined reference to `TIFFCleanup'
/usr/local/lib/liblept.a(tiffio.o): In function `getTiffResolution':
/home/utkrist/leptonica-1.69/src/tiffio.c:1155: undefined reference to `TIFFCleanup'
/usr/local/lib/liblept.a(tiffio.o): In function `freadHeaderTiff':
/home/utkrist/leptonica-1.69/src/tiffio.c:1320: undefined reference to `TIFFReadDirectory'
/home/utkrist/leptonica-1.69/src/tiffio.c:1326: undefined reference to `TIFFCleanup'
/usr/local/lib/liblept.a(tiffio.o): In function `readHeaderMemTiff':
/home/utkrist/leptonica-1.69/src/tiffio.c:1382: undefined reference to `TIFFReadDirectory'
/home/utkrist/leptonica-1.69/src/tiffio.c:1383: undefined reference to `TIFFClose'
/home/utkrist/leptonica-1.69/src/tiffio.c:1390: undefined reference to `TIFFClose'
/usr/local/lib/liblept.a(tiffio.o): In function `findTiffCompression':
/home/utkrist/leptonica-1.69/src/tiffio.c:1492: undefined reference to `TIFFGetFieldDefaulted'
/home/utkrist/leptonica-1.69/src/tiffio.c:1494: undefined reference to `TIFFCleanup'
/usr/local/lib/liblept.a(tiffio.o): In function `extractG4DataFromFile':
/home/utkrist/leptonica-1.69/src/tiffio.c:1599: undefined reference to `TIFFGetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:1602: undefined reference to `TIFFClose'
/home/utkrist/leptonica-1.69/src/tiffio.c:1606: undefined reference to `TIFFGetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:1607: undefined reference to `TIFFGetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:1608: undefined reference to `TIFFGetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:1611: undefined reference to `TIFFGetField'
/home/utkrist/leptonica-1.69/src/tiffio.c:1613: undefined reference to `TIFFClose'
/usr/local/lib/liblept.a(tiffio.o): In function `pixReadMemTiff':
/home/utkrist/leptonica-1.69/src/tiffio.c:2035: undefined reference to `TIFFReadDirectory'
/home/utkrist/leptonica-1.69/src/tiffio.c:2042: undefined reference to `TIFFClose'
/home/utkrist/leptonica-1.69/src/tiffio.c:2029: undefined reference to `TIFFClose'
/usr/local/lib/liblept.a(tiffio.o): In function `pixWriteMemTiffCustom':
/home/utkrist/leptonica-1.69/src/tiffio.c:2125: undefined reference to `TIFFClose'
/usr/local/lib/liblept.a(jpegio.o): In function `jpeg_error_do_not_exit':
/home/utkrist/leptonica-1.69/src/jpegio.c:1118: undefined reference to `jpeg_destroy'
/usr/local/lib/liblept.a(jpegio.o): In function `pixReadStreamJpeg':
/home/utkrist/leptonica-1.69/src/jpegio.c:259: undefined reference to `jpeg_std_error'
/home/utkrist/leptonica-1.69/src/jpegio.c:262: undefined reference to `jpeg_CreateDecompress'
/home/utkrist/leptonica-1.69/src/jpegio.c:265: undefined reference to `jpeg_set_marker_processor'
/home/utkrist/leptonica-1.69/src/jpegio.c:266: undefined reference to `jpeg_stdio_src'
/home/utkrist/leptonica-1.69/src/jpegio.c:267: undefined reference to `jpeg_read_header'
/home/utkrist/leptonica-1.69/src/jpegio.c:272: undefined reference to `jpeg_calc_output_dimensions'
/home/utkrist/leptonica-1.69/src/jpegio.c:310: undefined reference to `jpeg_start_decompress'
/home/utkrist/leptonica-1.69/src/jpegio.c:374: undefined reference to `jpeg_read_scanlines'
/home/utkrist/leptonica-1.69/src/jpegio.c:399: undefined reference to `jpeg_finish_decompress'
/home/utkrist/leptonica-1.69/src/jpegio.c:400: undefined reference to `jpeg_destroy_decompress'
/home/utkrist/leptonica-1.69/src/jpegio.c:336: undefined reference to `jpeg_read_scanlines'
/home/utkrist/leptonica-1.69/src/jpegio.c:315: undefined reference to `jpeg_start_decompress'
/usr/local/lib/liblept.a(jpegio.o): In function `freadHeaderJpeg':
/home/utkrist/leptonica-1.69/src/jpegio.c:491: undefined reference to `jpeg_std_error'
/home/utkrist/leptonica-1.69/src/jpegio.c:493: undefined reference to `jpeg_CreateDecompress'
/home/utkrist/leptonica-1.69/src/jpegio.c:494: undefined reference to `jpeg_stdio_src'
/home/utkrist/leptonica-1.69/src/jpegio.c:495: undefined reference to `jpeg_read_header'
/home/utkrist/leptonica-1.69/src/jpegio.c:496: undefined reference to `jpeg_calc_output_dimensions'
/home/utkrist/leptonica-1.69/src/jpegio.c:507: undefined reference to `jpeg_destroy_decompress'
/usr/local/lib/liblept.a(jpegio.o): In function `fgetJpegResolution':
/home/utkrist/leptonica-1.69/src/jpegio.c:545: undefined reference to `jpeg_std_error'
/home/utkrist/leptonica-1.69/src/jpegio.c:547: undefined reference to `jpeg_CreateDecompress'
/home/utkrist/leptonica-1.69/src/jpegio.c:548: undefined reference to `jpeg_stdio_src'
/home/utkrist/leptonica-1.69/src/jpegio.c:549: undefined reference to `jpeg_read_header'
/home/utkrist/leptonica-1.69/src/jpegio.c:562: undefined reference to `jpeg_destroy_decompress'
/usr/local/lib/liblept.a(jpegio.o): In function `pixWriteStreamJpeg':
/home/utkrist/leptonica-1.69/src/jpegio.c:699: undefined reference to `jpeg_std_error'
/home/utkrist/leptonica-1.69/src/jpegio.c:702: undefined reference to `jpeg_CreateCompress'
/home/utkrist/leptonica-1.69/src/jpegio.c:703: undefined reference to `jpeg_stdio_dest'
/home/utkrist/leptonica-1.69/src/jpegio.c:717: undefined reference to `jpeg_set_defaults'
/home/utkrist/leptonica-1.69/src/jpegio.c:732: undefined reference to `jpeg_set_quality'
/home/utkrist/leptonica-1.69/src/jpegio.c:754: undefined reference to `jpeg_start_compress'
/home/utkrist/leptonica-1.69/src/jpegio.c:757: undefined reference to `jpeg_write_marker'
/home/utkrist/leptonica-1.69/src/jpegio.c:797: undefined reference to `jpeg_write_scanlines'
/home/utkrist/leptonica-1.69/src/jpegio.c:800: undefined reference to `jpeg_finish_compress'
/home/utkrist/leptonica-1.69/src/jpegio.c:809: undefined reference to `jpeg_destroy_compress'
/home/utkrist/leptonica-1.69/src/jpegio.c:784: undefined reference to `jpeg_write_scanlines'
/home/utkrist/leptonica-1.69/src/jpegio.c:734: undefined reference to `jpeg_simple_progression'
/home/utkrist/leptonica-1.69/src/jpegio.c:699: undefined reference to `jpeg_std_error'
/home/utkrist/leptonica-1.69/src/jpegio.c:702: undefined reference to `jpeg_CreateCompress'
/home/utkrist/leptonica-1.69/src/jpegio.c:703: undefined reference to `jpeg_stdio_dest'
/usr/local/lib/liblept.a(pngio.o): In function `pixReadStreamPng':
/home/utkrist/leptonica-1.69/src/pngio.c:182: undefined reference to `png_create_read_struct'
/home/utkrist/leptonica-1.69/src/pngio.c:186: undefined reference to `png_create_info_struct'
/home/utkrist/leptonica-1.69/src/pngio.c:191: undefined reference to `png_create_info_struct'
/home/utkrist/leptonica-1.69/src/pngio.c:202: undefined reference to `png_init_io'
/home/utkrist/leptonica-1.69/src/pngio.c:218: undefined reference to `png_read_png'
/home/utkrist/leptonica-1.69/src/pngio.c:220: undefined reference to `png_get_rows'
/home/utkrist/leptonica-1.69/src/pngio.c:221: undefined reference to `png_get_image_width'
/home/utkrist/leptonica-1.69/src/pngio.c:222: undefined reference to `png_get_image_height'
/home/utkrist/leptonica-1.69/src/pngio.c:223: undefined reference to `png_get_bit_depth'
/home/utkrist/leptonica-1.69/src/pngio.c:224: undefined reference to `png_get_rowbytes'
/home/utkrist/leptonica-1.69/src/pngio.c:225: undefined reference to `png_get_color_type'
/home/utkrist/leptonica-1.69/src/pngio.c:226: undefined reference to `png_get_channels'
/home/utkrist/leptonica-1.69/src/pngio.c:336: undefined reference to `png_get_x_pixels_per_meter'
/home/utkrist/leptonica-1.69/src/pngio.c:337: undefined reference to `png_get_y_pixels_per_meter'
/home/utkrist/leptonica-1.69/src/pngio.c:342: undefined reference to `png_get_text'
/home/utkrist/leptonica-1.69/src/pngio.c:346: undefined reference to `png_destroy_read_struct'
/home/utkrist/leptonica-1.69/src/pngio.c:198: undefined reference to `png_destroy_read_struct'
/home/utkrist/leptonica-1.69/src/pngio.c:241: undefined reference to `png_destroy_read_struct'
/home/utkrist/leptonica-1.69/src/pngio.c:248: undefined reference to `png_get_PLTE'
/home/utkrist/leptonica-1.69/src/pngio.c:187: undefined reference to `png_destroy_read_struct'
/home/utkrist/leptonica-1.69/src/pngio.c:192: undefined reference to `png_destroy_read_struct'
/home/utkrist/leptonica-1.69/src/pngio.c:261: undefined reference to `png_destroy_read_struct'
/usr/local/lib/liblept.a(pngio.o): In function `fgetPngResolution':
/home/utkrist/leptonica-1.69/src/pngio.c:534: undefined reference to `png_create_read_struct'
/home/utkrist/leptonica-1.69/src/pngio.c:537: undefined reference to `png_create_info_struct'
/home/utkrist/leptonica-1.69/src/pngio.c:551: undefined reference to `png_init_io'
/home/utkrist/leptonica-1.69/src/pngio.c:552: undefined reference to `png_read_png'
/home/utkrist/leptonica-1.69/src/pngio.c:554: undefined reference to `png_get_x_pixels_per_meter'
/home/utkrist/leptonica-1.69/src/pngio.c:555: undefined reference to `png_get_y_pixels_per_meter'
/home/utkrist/leptonica-1.69/src/pngio.c:559: undefined reference to `png_destroy_read_struct'
/home/utkrist/leptonica-1.69/src/pngio.c:545: undefined reference to `png_destroy_read_struct'
/home/utkrist/leptonica-1.69/src/pngio.c:538: undefined reference to `png_destroy_read_struct'
/usr/local/lib/liblept.a(pngio.o): In function `pixWriteStreamPng':
/home/utkrist/leptonica-1.69/src/pngio.c:701: undefined reference to `png_create_write_struct'
/home/utkrist/leptonica-1.69/src/pngio.c:705: undefined reference to `png_create_info_struct'
/home/utkrist/leptonica-1.69/src/pngio.c:716: undefined reference to `png_init_io'
/home/utkrist/leptonica-1.69/src/pngio.c:721: undefined reference to `png_set_compression_level'
/home/utkrist/leptonica-1.69/src/pngio.c:754: undefined reference to `png_set_IHDR'
/home/utkrist/leptonica-1.69/src/pngio.c:764: undefined reference to `png_set_pHYs'
/home/utkrist/leptonica-1.69/src/pngio.c:804: undefined reference to `png_set_text'
/home/utkrist/leptonica-1.69/src/pngio.c:808: undefined reference to `png_write_info'
/home/utkrist/leptonica-1.69/src/pngio.c:840: undefined reference to `png_set_rows'
/home/utkrist/leptonica-1.69/src/pngio.c:843: undefined reference to `png_write_image'
/home/utkrist/leptonica-1.69/src/pngio.c:844: undefined reference to `png_write_end'
/home/utkrist/leptonica-1.69/src/pngio.c:886: undefined reference to `png_destroy_write_struct'
/home/utkrist/leptonica-1.69/src/pngio.c:712: undefined reference to `png_destroy_write_struct'
/home/utkrist/leptonica-1.69/src/pngio.c:781: undefined reference to `png_set_PLTE'
/home/utkrist/leptonica-1.69/src/pngio.c:791: undefined reference to `png_set_gAMA'
/home/utkrist/leptonica-1.69/src/pngio.c:860: undefined reference to `png_write_rows'
/home/utkrist/leptonica-1.69/src/pngio.c:882: undefined reference to `png_write_end'
/home/utkrist/leptonica-1.69/src/pngio.c:706: undefined reference to `png_destroy_write_struct'
/home/utkrist/leptonica-1.69/src/pngio.c:877: undefined reference to `png_write_rows'
/home/utkrist/leptonica-1.69/src/pngio.c:829: undefined reference to `png_destroy_write_struct'
/usr/local/lib/liblept.a(zlibmem.o): In function `zlibCompress':
/home/utkrist/leptonica-1.69/src/zlibmem.c:121: undefined reference to `deflateInit_'
/home/utkrist/leptonica-1.69/src/zlibmem.c:132: undefined reference to `deflate'
/home/utkrist/leptonica-1.69/src/zlibmem.c:144: undefined reference to `deflateEnd'
/usr/local/lib/liblept.a(zlibmem.o): In function `zlibUncompress':
/home/utkrist/leptonica-1.69/src/zlibmem.c:201: undefined reference to `inflateInit_'
/home/utkrist/leptonica-1.69/src/zlibmem.c:212: undefined reference to `inflate'
/home/utkrist/leptonica-1.69/src/zlibmem.c:224: undefined reference to `inflateEnd'
collect2: ld returned 1 exit status
make[2]: *** [getText] Error 1
make[1]: *** [CMakeFiles/getText.dir/all] Error 2
make: *** [all] Error 2
I've faced such problems several times, and what I do is to instruct CMake to generate a UNIX Makefile, and then look at what g++ command the Makefile is executing.
I know its not a great answer, but maybe It'll help.

Objective-C #implementation variables visibility

I got two classes, which implementation contains an array named "geometryCoords", in "Corridor" class it is initialized in declaration, and in "RhombusArray" it is done in the "init" method:
GLfloat _geometryCoords[]={/*Values here*/};
GLfloat _geometryCoords[];
...//In the init method
_geometryCoords = (GLfloat*)malloc(somevalue);
for(...){/*Assignment*/}
While debugging this method i noticed that "geometryCoords" has the values of the first class' array before the initialization code is passed. After changing the declaration of array in "RhombusArray" from:
GLfloat _geometryCoords[];
to
GLfloat* _geometryCoords;
i got an "Apple Mach-o linker error: duplicate symbol _geometryCoords in /BlaBla/Corridor.o and /BlaBla/RhombusArray.o".
Both of those classes' headers are imported to the .mm file and removing one of them solves the conflict.
How should i handle this problem?
Both of these arrays must have global scope (i.e. they are declared outside of a function and outside of a class interface) for you to get the linker error and the other issue. Declare them like this:
static GLfloat _geometryCoords[]={/*Values here*/};
//^^^^ this is the new bit
The static keyword makes the symbol visible only within the compilation unit (the .m file) in which they are declared.