xcode


Link dylib library


I'm trying to link a dylib to my makefile on Mac, but Clang gives this message:
Undefined symbols for architecture x86_64:
"_zbesj_wrap", referenced from:
sp_bessel::besselJ(double, std::__1::complex<double>) in besselJ.o
"_zbesy_wrap", referenced from:
sp_bessel::besselJ(double, std::__1::complex<double>) in besselJ.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 installed the library in /usr/lib, where I can see libcomplex_bessel.0.6.0.dylib and libcomplex_bessel.dylib.
This is my makefile:
OBJS = main.o besselJ.o
CC = c++
CFLAGS = -std=c++11 -stdlib=libc++
LIBS = -L/usr/lib -lcomplex_bessel
PROGRAM_NAME = test
all: $(PROGRAM_NAME)
$(PROGRAM_NAME): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $#
main.o: main.cpp
$(CC) $(CFLAGS) -c $< -o $#
besselJ.o: besselJ.cpp
$(CC) $(CFLAGS) -c $< -o $# $(LIBS)
After reading other questions, I tried different combinations for -L and -l but nothing worked. Sorry but it's my first time with external libraries...
I changed my makefile to this:
OBJS = main.o besselJ.o
CC = c++
CFLAGS = -std=c++11 -stdlib=libc++
LIBS = -L/usr/lib -lcomplex_bessel
PROGRAM_NAME = test
all: $(PROGRAM_NAME)
$(PROGRAM_NAME): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $# $(LIBS)
main.o: main.cpp
$(CC) $(CFLAGS) -c $< -o $#
besselJ.o: besselJ.cpp
$(CC) $(CFLAGS) -c $< -o $#
but I still have problems, I get this message:
c++ -std=c++11 -stdlib=libc++ main.o besselJ.o -o test -L/usr/lib -lcomplex_bessel
ld: library not found for -lcomplex_bessel
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [test] Error 1
Ok, I think I solved it using xcode-select --install: other users had the same problem with libraries after updating it.
You need to pass libs to linker, not to the compiler:
OBJS = main.o besselJ.o
CC = c++
CFLAGS = -std=c++11 -stdlib=libc++
LIBS = -L/usr/lib -lcomplex_bessel
PROGRAM_NAME = test
all: $(PROGRAM_NAME)
$(PROGRAM_NAME): $(OBJS)
$(CC) $(OBJS) -o $# $(LIBS)
main.o: main.cpp
$(CC) $(CFLAGS) -c $< -o $#
besselJ.o: besselJ.cpp
$(CC) $(CFLAGS) -c $< -o $#

Related Links

Xcode compiler plugins & native build settings for platforms
Where can I find “Load Symbols Lazily” option in Xcode6?
Unable to compile phonegap for iOS
Framework keeps searching in the wrong place - how to use install_name_tool?
Status Bar Not Hiding
Use of undeclared identifier Xcode
ViewController.Type does not have a member named
#include files not found in Apple Open Source software
Setting in Xcode to check values when I archive
When have I to use “Prefer margin relative”?
Delay when running ios8 Extension from debugger
Way to Programmatically Reboot iOS Device?
Add many frameworks to Xcode at once
Why Can't I Drag IBAction from Storyboard to Swift File?
Override Xcode's default templates
XCODE : Changing which view controller BACK button segues to

Categories

HOME
jboss
android-espresso
powerbi
android-studio
enums
add-on
mathematical-optimization
fogbugz
dependencies
angular2-template
sharepoint-online
eddystone
spring-security-oauth2
lda
solution
phpstorm-2017.1
documentum
chromecast
android-externalstorage
sslhandshakeexception
smartgwt
heap-dump
nest-api
mixpanel
cloudsim
spyder
gollum-wiki
qa
perfino
password-generator
ruby-daemons
marquee
vcenter
gnu-classpath
xerces-c
aurelia-cli
cloudera-quickstart-vm
ng-repeat
microsoft-ui-automation
reset
stat
right-click
resampling
cloudera-sentry
transparency
autorelease
ssi
rm
nothing
nonlinear-functions
zend-server
openerp-6
pyaudio
maven-release-plugin
perforce-integrate
maximize
simian
accessibilityservice
currency-exchange-rates
onepage-checkout
android-expansion-files
flush
wepay
outlook.com
cfwheels
dnx50
scala-swing
signed
jolie
adhoc-polymorphism
dnsjava
inputbox
oracle-adf-mobile
ecos
webmethod
mfmessagecomposeview
webaii
cloo
discovery
notin
android-authenticator
red-system
linkbutton
stretch
viewpagerindicator
server-name
pcspim
firebird1.5
series-40
type-safety
drawimage
qt-mobility
database-deadlocks
kernel32
uninstaller
j2mepolish
tacit-programming
rtti
html-generation

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App