gcc -dynamiclib foo.c -o libfoo.dylib
gcc main.c -L. -lfoo -o main
To specify a install_name
of a dylib, use -install_name
in gcc
gcc -dynamiclib foo.c -install_name -o libfoo.dylib
The install_name
of dylib will be write in main
otool -L <executable>
Check all the dylib linked in main
, where the
install_name
of a dylib is the path where main
links the dylib.
example:
otool -L main
otool -D <dylib>
Check the install_name
of a dylib
example:
otool -D libfoo.dylib
install_name_tool -id <new name> <dylib>
Change the install_name_tool
of libfoo.dylib
to ../libfoo.dylib
example:
install_name_tool -id ../libfoo.dylib libfoo.dylib
install_name_tool -change <old value> <new value> <executable>
example:
install_name_tool -change ../libfoo.dylib ../../libfoo.dylib main
NOTE: One more method, if install_name
of a dylib is not corret, setting
the environment variable $DYLD_LIBRARY_PATH
to the path where the
dylib is can let executable find the dylib successfully. More info can
see man dyld
.
More info see
mac/dylib
.
brew install automake libtool doxygen libdnet
Use build process from the source of libnet
for instance.
.configure
./configure --prefix=<where you want to install>
Makefile
heremake
make install
Generally the the install_name
of libnet.dylib
will be set properly.
Use the method above configure, make, make install
with
libnet-1.2-rc3.tar.gz
(recommand)
Or use the method show in BUILD-FROM-GIT.txt
Jacob Pan ( jacobpan3g.github.io/ )
To convert file encode from GBK to UTF-8
find <dir> -type d -exec mkdir -p <utf dir>/{} \;
find <dir> -type f -exec bash -c "iconv -f GBK -t UTF-8 {} > <utf dir>/{}" \;
Above, iconv -f GBK -t UTF-8 <file> > <out file>
can convert encode. In Linux, option -o <out file>
can instead by >
.
{}
in the find -exec
command represents each line of the output of find
.
Jacob Pan ( jacobpan3g.github.io )
Show the default xcode in mac os x:
$ xcode-select -p
Change system default xcode
# xcode-select -switch /Applications/Xcode.app
If there are more than one xcode installed in mac os x, the second one will be named “xcode 2”. Sometimes, it’ll raise some errors because the “ “(space) in the name.
For instance, to build libnet, I followed the BUILD-FROM-GIT.txt
at the top of project. Because my default xcode is named “xcode 2”, it throw an error as
/bin/sh: /Applications/Xcode: No such file or directory
. After I switched to “xcode” using the cmd above, the build process success.
Jacob Pan ( jacobpan3g.github.io/ )