This is the procedure I am following to create dylib and using it ,please help me I am new to dylib .
I am creating dylib for c++ in xcode I have given Installation Directory #rpath this is my C++ code
Add.hpp:
#define EXPORT __attribute__((visibility("default")))
class Add
{
public:
EXPORT void HelloWorld(const char *);
EXPORT int AddTwo(int a,int b);
};
Add.cpp:
void Add::HelloWorld(const char * s)
{
AddPriv *theObj = new AddPriv;
theObj->HelloWorldPriv(s);
delete theObj;
};
int Add::AddTwo(int a, int b)
{
return a+b;
}
After creating dylib in other project using Copy files in build phases, copying it to Frameworks, I am able to see it in Sample.App/Contents/Frameworks/Mylib.dylib. In Build Settings, Runpath Search Paths is set to #executable_path/../Frameworks. I added header in root folder given Header Search Paths $(SRCROOT).
The error I get is:
Undefined symbols for architecture x86_64:
"Add::AddTwo(int, int)", referenced from:
-[ViewController viewDidLoad] in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Edit:
$ nm -gU ****/AddTest.app/Contents/Frameworks/libAdd.dylib
0000000000001170 T __ZN3Add10HelloWorldEPKc
0000000000001220 T __ZN3Add6AddTwoEii
able to see symboles in lib and otool output is:
$ otool -L libAdd.dylib
#rpath/libAdd.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
resolved by adding library to Link Binary with Libraries in build phases
Related
I am making a package manager, and would like to ensure the packages use the correct dependent library by setting rpath option at compile time. But it surprised me in OS X (10.11), here is the problem:
$ otool -L /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
/opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951:
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/opt/starman/software/isl/0.17.1/104994def2b7fb2dae7950b42205eb718a46ee0c/lib/libisl.15.dylib (compatibility version 18.0.0, current version 18.1.0)
/opt/starman/software/mpc/1.0.3/6058925218009b8ab17e07333dc54de334134f6e/lib/libmpc.3.dylib (compatibility version 4.0.0, current version 4.0.0)
/opt/starman/software/mpfr/3.1.4/f142dfcda3b56650a8c9cfe2fdd09ffdf7283a00/lib/libmpfr.4.dylib (compatibility version 6.0.0, current version 6.4.0)
/opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib (compatibility version 14.0.0, current version 14.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
see gmp version is 14.0.0.
$ /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
dyld: Library not loaded: /opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib
Referenced from: /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
Reason: Incompatible library version: f951 requires version 14.0.0 or later, but libgmp.10.dylib provides version 13.0.0
Trace/BPT trap: 5
It says gmp in the correct path is not loaded since its version is 13.0.0, but it is 14.0.0! I know I have an older version gmp installed in another path, so after I remove its lib path from DYLD_LIBRARY_PATH, the problem is gone, but shouldn't rpath solve this problem?
Why dyld prints the correct path of gmp, but actually uses the wrong old? Is there any tricks in OS X? Thanks for help!
EDIT 1:
The version of /opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib is checked as
$ otool -l /opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib
...
cmdsize 120
name /opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib (offset 24)
time stamp 1 Thu Jan 1 08:00:01 1970
current version 14.0.0
compatibility version 14.0.0
...
And the older gmp is
$ otool -l /opt/software/gmp/6.0.0a/0/lib/libgmp.10.dylib
...
name #rpath/lib/libgmp.dylib (offset 24)
time stamp 1 Thu Jan 1 08:00:01 1970
current version 13.0.0
compatibility version 13.0.0
...
EIDT 2
According to 0xced, I run debug the loading process as (The full output is here):
$ export DYLD_PRINT_LIBRARIES="1"
$ /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
dyld: loaded: /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
dyld: loaded: /usr/lib/libiconv.2.dylib
dyld: loaded: /opt/starman/software/isl/0.17.1/104994def2b7fb2dae7950b42205eb718a46ee0c/lib/libisl.15.dylib
dyld: loaded: /opt/software/packman.active/lib/libmpc.3.dylib
dyld: loaded: /opt/software/packman.active/lib/libmpfr.4.dylib
dyld: loaded: /opt/software/packman.active/lib/libgmp.10.dylib
dyld: unloaded: /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
dyld: unloaded: /opt/starman/software/isl/0.17.1/104994def2b7fb2dae7950b42205eb718a46ee0c/lib/libisl.15.dylib
dyld: unloaded: /opt/software/packman.active/lib/libmpc.3.dylib
dyld: unloaded: /opt/software/packman.active/lib/libmpfr.4.dylib
dyld: unloaded: /opt/software/packman.active/lib/libgmp.10.dylib
dyld: Library not loaded: /opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib
Referenced from: /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
Reason: Incompatible library version: f951 requires version 14.0.0 or later, but libgmp.10.dylib provides version 13.0.0
Trace/BPT trap: 5
I don't understand why the f951 binary would load /opt/software/gmp/6.0.0a/0/lib/libgmp.10.dylib (version 13) rather than /opt/starman/software/gmp/6.1.0/0ec8ef118d09cb33f83559685d006f56a74f865c/lib/libgmp.10.dylib (version 14) which is specified with an absolute path and not a relative #rpath.
Maybe it’s loaded indirectly via another library, e.g. libisl.15.dylib, libmpc.3.dylib or libmpfr.4.dylib which could have an #rpath reference to libgmp.10.dylib?
To diagnose this issue, I suggest you to run the main executable like this:
$ DYLD_PRINT_RPATHS=YES /opt/starman/software/gcc/6.1.0/83894f21d07366be296600ec031ae4f6241381d9/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/f951
This will print all rpath expansions (both failure and success) and will probably give you the answer to your question.
I installed EiffelStudio like this:
1) Downloaded Eiffel_15.12_gpl_98497-macosx-x86-64.tar.bz2 from official page.
2)
cd /usr/local
tar xvfj /path/Eiffel_15.12.tar.bz2
3)
export ISE_EIFFEL=/usr/local/Eiffel_15.12
export ISE_PLATFORM=macosx-x86-64
export PATH=$PATH:$ISE_EIFFEL/studio/spec/$ISE_PLATFORM/bin
Then I type "ec" to run the command-line compiler and this is the output:
dyld: Library not loaded: /opt/local/lib/libiconv.2.dylib
Referenced from: /usr/local/Eiffel_15.12/studio/spec/macosx-x86-64/bin/ec
Reason: Incompatible library version: ec requires version 8.0.0 or later, but libiconv.2.dylib provides version 7.0.0
Trace/BPT trap: 5
Any solution?
PS: Im using OSX 10.11.4
PPS: When i run
otool -L $(which ec)
I get
/usr/local/Eiffel_15.12/studio/spec/macosx-x86-64/bin/ec:
/opt/local/lib/libiconv.2.dylib (compatibility version 8.0.0, current version 8.1.0)
...
EDIT: I found this link that helps me
https://stackoverflow.com/a/19016967/6273708
But know the error message is
dyld: Library not loaded: /opt/local/lib/libgtk-x11-2.0.0.dylib
Referenced from: /usr/local/Eiffel_15.12/studio/spec/macosx-x86-64/bin/ec
Reason: image not found
Trace/BPT trap: 5
Since the recent update Mavericks, I have a problem linking with the library json_spirit.
I installed the new Command Line Tools, but I'm using gcc47 installed via macports. Json spirit (v4.06) has been compiled with the same gcc (after the update).
gcc (MacPorts gcc47 4.7.3_3) 4.7.3
I boiled it down to the following example :
test.cpp
#include <iostream>
#include "json_spirit_reader_template.h"
#include "json_spirit_writer_template.h"
#include "json_spirit_writer.h"
int main(int argc, char **argv) {
json_spirit::mValue a;
std::string s("[]");
json_spirit::read_string(s, a);
std::cout << json_spirit::write_formatted(a) << std::endl;
return 0;
}
which I compile with the following :
g++ -I/usr/local/include test.cpp -o test -L/usr/local/lib -ljson_spirit
And it gives this error :
Undefined symbols for architecture x86_64:
"json_spirit::write_formatted(json_spirit::Value_impl<json_spirit::Config_map<std::basic_strin g<char, std::char_traits<char>, std::allocator<char> > > > const&)", referenced from:
_main in ccwUclng.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
And finally, using "nm -g /usr/local/lib/libjson_spirit.a | grep write_formatted" :
nm: no name list
0000000000000150 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEE
000000000003afa8 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEE.eh
0000000000000120 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEERNS2_13basic_ostreamIcS5_EE
000000000003af80 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEERNS2_13basic_ostreamIcS5_EE.eh
0000000000000270 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEE
000000000003b118 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEE.eh
0000000000000240 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEERNS2_13basic_ostreamIwS5_EE
000000000003b0c8 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_10Config_mapINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEERNS2_13basic_ostreamIwS5_EE.eh
0000000000000090 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEE
000000000003aeb0 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEE.eh
0000000000000060 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEERNS2_13basic_ostreamIcS5_EE
000000000003ae88 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEEERNS2_13basic_ostreamIcS5_EE.eh
0000000000000210 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEE
000000000003b0a0 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEE.eh
00000000000001e0 T __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEERNS2_13basic_ostreamIwS5_EE
000000000003b078 S __ZN11json_spirit15write_formattedERKNS_10Value_implINS_13Config_vectorINSt3__112basic_stringIwNS2_11char_traitsIwEENS2_9allocatorIwEEEEEEEERNS2_13basic_ostreamIwS5_EE.eh
I don't know how to read the nm output, so I may be missing something obvious.
I've tried to install and uninstall every component (boost ..) one by one, compiling with the gcc from macports and / or the default, which is :
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
Well, this is a half answer, because I never really got to explain exactly what happened, but I fixed it, so..
The answer was to rebuild boost from scratch, (icu as well) with the new system and the same compiler everywhere, for me it's gcc 4.7.3 installed with macports.
Also, I was trying to upgrade from boost 1.53 to boost 1.54, so it may have been part of the problem, but now anyway I went back to boost 1.53.
I try to build a simple Qt 5 program on Mac. But I failed.
The code is very simple:
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication app (argc, argv);
return app.exec();
}
I used:
clang++ -I ~/Qt5.0.0/5.0.0/clang_64/include -L/Users/crazylion/Qt5.0.0/5.0.0/clang_64/lib test.cpp
Then I got this error:
Undefined symbols for architecture x86_64:
"QApplication::exec()", referenced from:
_main in test-jPGORy.o
"QApplication::QApplication(int&, char**, int)", referenced from:
_main in test-jPGORy.o
"QApplication::~QApplication()", referenced from:
_main in test-jPGORy.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Is there anything i missing?
Firstly, don't compile and link Qt projects by hand; use qmake and project files.
Run qmake -project in your source directory to generate a basic project file.
Edit the project file and add the following line: QT += widgets
Now run qmake to generate a makefile.
Now run make to build your program.
Secondly, you can simply #include <QApplication>
If you want to use clang++ in favor of qmake, you need to specify libraries to link against to, along with the library directory (which you supplied).
clang++ -I ~/Qt5.0.0/5.0.0/clang_64/include -L/Users/crazylion/Qt5.0.0/5.0.0/clang_64/lib -lQtCore -lQtGui test.cpp
I had the same problems and it seems to me that there is some sort of bug in the release it gave me some errors because out of a fresh install (using qt creator) i didn't have some obscure qt library (not the normal qt5 modules but some sort of library in development) so I tend to think that it could be qt's problem
That said I have some questions to better understand:
-are you using a IDE?
-if you are using one which is it?
-are you including all the modules in the *.pro for quake?
-have you used 4.8 version, did you experienced these problems with that?
P.S. if you do not have any particular necessity I suggest you to stick to version 4.8 for some time (as I am doing without problem) since 5.0 is just been released
Steps:
1. sudo port boost
The boost file installed in /opt/local/boost, library files are in /opt/local/lib
2. use XCode to create c++ project
#include <iostream>
#include <boost/asio.hpp>
int main () {
return 0;
}
3. set XCode to find out boost
in "Build Settings" -> "HEADER_SEARCH_PATHS"
in both Debug and Release add path /opt/local/include
4. "Build Settings" -> "LIBRARY_SEARCH_PATHS" --> add /opt/local/lib both for debug and release.
5. build program and failed.
Error Messages,
Undefined symbols for architecture x86_64:
"boost::system::generic_category()", referenced from:
___cxx_global_var_init1 in main.o
___cxx_global_var_init2 in main.o
"boost::system::system_category()", referenced from:
___cxx_global_var_init3 in main.o
boost::asio::error::get_system_category() in main.o
"boost::asio::error::get_netdb_category()", referenced from:
___cxx_global_var_init5 in main.o <br>
"boost::asio::error::get_addrinfo_category()", referenced from:
___cxx_global_var_init6 in main.o <br>
"boost::asio::error::get_misc_category()", referenced from:
___cxx_global_var_init7 in main.o <br>
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Am I wrong in the procedure?
You need to link with Boost.System, which should be in /opt/local/lib/libboost_system (with some suffix, that depends on how you built boost)
Add that to your Xcode project.
select on your "targets"
in "Link Binary with libraries" section under "build phases" tab, add boost library.
if install via MacPort, the boost will be at /opt/local/lib,
if install via brew, the boost will be at /usr/local/Cellar/boost ,
if build by yourself, it will be at /usr/local/lib by default or yourBoostLib/stage/lib