objective c - Unable to link a static C library in an Obj-C project (Xcode 4.6.3) -


i'm trying build basic ftp client using libftp. i've compiled , archived libftp.a , placed in /usr/local/lib. necessary headers i've placed in /usr/local/include/ftp.

under build settings, i've set "header search paths" /usr/local/include, , i've set "library search paths" /usr/local/lib. "other linker flags", i've added -lftp.

here shell of c++ class:

connector.h:

#include <stdlib.h> #include <ftp/ftp.h> #include <stdio.h>  class connector{     private:         ftpconnection *connection;     public:         connector();         ~connector();          bool connect(const char *hostname, const char *port);     }; 

connector.cc:

#include "connector.h"  connector::connector(){     }  connector::~connector(){     }  bool connector::connect(const char *hostname, const char *port){     ftpgetaddresses(hostname, port);     printf("connected!\n");     return true;     } 

upon compiling, error get:

undefined symbols architecture x86_64: "ftpgetaddresses(char const*, char const*)", referenced from: connector::connect(char const*, char const*) in connector.o ld: symbol(s) not found architecture x86_64 clang: error: linker command failed exit code 1 (use -v see invocation)

it's worth noting part of cocoa project, connector class #included in appdelegate, of course obj-c class. of obj-c source files have .mm extension.

i lib in working order, have no issue compiling program on command line gcc ... -lftp. it's problem xcode.

well, appears talked myself through own problem. typing last part of question, realized issue linking c library in c++ source file. gcc compile fine on command line, g++ gave me same error xcode. 1 google search later found this link, solved problem beautifully. basically, if want c library compatible c++, need add

#ifdef __cplusplus extern "c" { #endif 

at top of library header file, , add

#ifdef __cplusplus } #endif 

at bottom of file. i'll leave question here hoping else in future.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -