Linking errors with external library, XCode 3.0

Hi,

I’m trying to compile some oF stuff using the external libcurl library.
So far I’m having trouble iinking.
I’ve tried putting ‘/usr/lib’ in the Library Search Paths project setting, as well as ‘-lcurl’ in the Other Linking Flags section of the Linking project prefs. It still complains about missing symbols. Any ideas? What am I doing wrong? The libcurl dynamic libraries all reside in /usr/lib/

EDIT:
By the way the following works…

  
  
#include <curl/curl.h>  
  
int main() {  
  
CURL *handle;  
  
handle = curl_easy_init();  
curl_easy_setopt(handle, CURLOPT_URL, "[http://www.google.com/");](http://www.google.com/");)  
curl_easy_perform(handle);  
  
return 0;  
}  
  

Then I do:

  
  
g++ -c main.cpp   
g++ -L/usr/lib -lcurl -lssl -lcrypto -lz main.o  
  

And this works…but putting

  
-L/usr/lib -lcurl -lssl -lcrypto -lz  
  

in Other Linker Flags in XCode doesn’t work.

Hi - can you send me the errors and warnings you get?

I am on Xcode 3.0 as well so I will give it a go over here.

Theo

The code above is not my code, just demo code that I knew worked.

My errors are just your basic “I can’t find your library” linker errors:

  
  
Building target “openFrameworks” of project “openFrameworks” with configuration “Debug” — (6 errors)  
	    cd /Users/grimus/dev/of_preRelease_v0.04_xcode/myapps/caterwaul  
    /Developer/usr/bin/g++-4.0 -o /Users/grimus/dev/of_preRelease_v0.04_xcode/myapps/caterwaul/openFrameworksDebug.app/Contents/MacOS/openFrameworksDebug -L/Users/grimus/dev/of_preRelease_v0.04_xcode/myapps/caterwaul -L/Users/grimus/dev/of_preRelease_v0.04_xcode/myapps/caterwaul/../../libs/freeimage/lib -L/Users/grimus/dev/of_preRelease_v0.04_xcode/myapps/caterwaul/../../libs/fmodex/lib -L/Users/grimus/dev/of_preRelease_v0.04_xcode/myapps/caterwaul/../../libs/freetype/lib -L/sw/lib -F/Users/grimus/dev/of_preRelease_v0.04_xcode/myapps/caterwaul -filelist /Users/grimus/dev/of_preRelease_v0.04_xcode/myapps/caterwaul/build/openFrameworks.build/Debug/openFrameworks.build/Objects-normal/i386/openFrameworksDebug.LinkFileList -framework GLUT -framework ApplicationServices -framework QuickTime -framework CoreServices -framework Carbon -framework OpenGL -framework AGL -framework CoreAudio -framework AudioToolbox -framework CoreFoundation /Users/grimus/dev/of_preRelease_v0.04_xcode/myapps/caterwaul/../../libs/freeimage/lib/freeimage.a -lfmodex /Users/grimus/dev/of_preRelease_v0.04_xcode/myapps/caterwaul/../../libs/freetype/lib/freetype.a -arch i386 -mmacosx-version-min=10.4 -framework Carbon -isysroot /Developer/SDKs/MacOSX10.4u.sdk  
Undefined symbols:  
  "_curl_formfree", referenced from:  
      HTTPUploader::uploadFile(char const*, char const*)in httpUploader.o  
  "_curl_easy_perform", referenced from:  
      HTTPUploader::uploadFile(char const*, char const*)in httpUploader.o  
  "_curl_formadd", referenced from:  
      HTTPUploader::uploadFile(char const*, char const*)in httpUploader.o  
      HTTPUploader::uploadFile(char const*, char const*)in httpUploader.o  
  "_curl_easy_init", referenced from:  
      HTTPUploader::HTTPUploader()in httpUploader.o  
  "_curl_easy_cleanup", referenced from:  
      HTTPUploader::~HTTPUploader()in httpUploader.o  
  "_curl_easy_setopt", referenced from:  
      HTTPUploader::uploadFile(char const*, char const*)in httpUploader.o  
      HTTPUploader::uploadFile(char const*, char const*)in httpUploader.o  
ld: symbol(s) not found  
collect2: ld returned 1 exit status  
		  "_curl_formfree", referenced from:  
		      HTTPUploader::uploadFile(char const*, char const*)in httpUploader.o  
		  "_curl_easy_perform", referenced from:  
		      HTTPUploader::uploadFile(char const*, char const*)in httpUploader.o  
		  "_curl_formadd", referenced from:  
		      HTTPUploader::uploadFile(char const*, char const*)in httpUploader.o  
		      HTTPUploader::uploadFile(char const*, char const*)in httpUploader.o  
		  "_curl_easy_init", referenced from:  
		      HTTPUploader::HTTPUploader()in httpUploader.o  
		  "_curl_easy_cleanup", referenced from:  
		      HTTPUploader::~HTTPUploader()in httpUploader.o  
		  "_curl_easy_setopt", referenced from:  
		      HTTPUploader::uploadFile(char const*, char const*)in httpUploader.o  
		      HTTPUploader::uploadFile(char const*, char const*)in httpUploader.o  
		ld: symbol(s) not found  
		collect2: ld returned 1 exit status  
Build failed (6 errors)  

I’m new to XCode so I’m still finding my way around. Now I’ve discovered the full compile command-line output…and it seems like the settings in the preferences are being ignored.

I finally got it linking by creating a short-cut to “/usr” in the finder sidebar using “Apple+T”, and then adding the libcurl.dyn library to the openFrameworks target by right clicking the target and selecting Add->Existing Files and then using my short-cut to navigate to /usr/lib (as by default its hidden).

I’d still like to know how to set custom linking flags though…any ideas?

don’t know if this is helpful, but this app:
http://openframeworks.cc/files/of-preRe-…-craper.zip
is OF w/ a scraper addon we are developing that uses libcurl – could be helpful…

okay here is how I got it working:

In project settings -> search paths -> library search paths
add

/usr/lib/

In project settings -> linking -> other linker flags
add

-lcurl -lssl -lcrypto

The clean all and compile and it should compile fine.
Cheers,
Theo

thanks for the scrapper!
it is totally sick : )

Hmmm. that’s what I had previously tried and it didn’t work.

So I created a new empty project and used the code in the above main.cpp but still got linker errors following the steps you just made.

I can get it to link by adding the library to the target, but not by the Other Linker Flags method…weird.

Do those compile flags show up in your compile output message window? I’m guessing they do on your machine.

hey sorry - the settings need to be put into the target settings not project settings.

So if you go down to

Targets -> openFrameworks in the sidebar

Highlight it and do get info.

The put the flags and paths that were in the project settings in there.
Also “/usr/lib/” should be quoted.

Then it compiles fine for me with this code in testApp::setup

  
CURL *handle;   
  
handle = curl_easy_init();   
curl_easy_setopt(handle, CURLOPT_URL, "[http://www.google.com/");](http://www.google.com/");)   
curl_easy_perform(handle);  

and

  
#include <curl/curl.h>   
  

in testApp.h

OK thanks that worked.
That’s really weird. The Library Search Path from the Project Settings gets set, but the linker flags don’t. This surely can’t be the way it is supposed to work?

Thanks for the demo scraper Zach…good to see the new polygon example as well.

Oh yeah, the code I was linking is an openframeworks and libcurl port of Daniel Schiffman’s “upload” Processing app - http://www.shiffman.net/2006/05/02/upload/
I’ll post it once my project is finished. It works well as a cheap alternative to a live video stream.

awesome!

I would be keen to check that out.
Theo

yeah me too ! that’s great

we’ve been interested in creating publishing automatically OF sketches (ie, making it easy to upload code and images online, so this could be really helpful for that…)

I am going to be adding threading to the ofScraper class, so that may be helpful as well for what you are doing - threading is pretty useful for libCurl, because it’s completely blocking when you do web calls etc (unless you use the alternative model – there is a non-blocking approach, but I couldn’t get my head around it). I have to say that libcurl is pretty amazing – and it support a number of really useful protocols, etc.

take care!!
zach

Threading would be great - a couple of times when I ran the ofScraper I thought it had hung…but I guess it was just the blocking mechanism that took over the app.

Would it be too advanced to have an oF threading example perhaps? With all the dual processors out there these days it would be good to take advantage of the extra processing power…and also provide a way for people to push heavy calculations out to a thread.

and yeah libcurl is crazy…it does all sorts of things!