2015-12-07 218 views
0

我想將一個external library called SVL (simple vector library)包含到C++中。我遇到了很多麻煩。我正在使用Mac OSX,而​​該庫的README僅針對Windows。如何在C++中包含外部庫?

我做

make clean 
make 

此創建的庫文件libsvl.alibsvl.dbg.a。我看到在READMEof the file中,它表示將其包含爲svl/vec3.h左右用於不同的標題。但是,當我嘗試這樣做時,它不起作用,仍然說,

vertex.hh:9:10: fatal error: 'svl/Vec3.h' file not found 
#include <svl/Vec3.h> 
    ^
1 error generated. 
vertex.cc:10:10: fatal error: 'svl/Vec3.h' file not found 
#include <svl/Vec3.h> 

你能建議我什麼我錯過?我可能需要更好地定義圖書館的路徑或做一些不同的事情。

從其他代碼庫文件中的相對路徑是../svl-1.5/lib/libsvl.a

化妝配置文件

# 

# Mac OSX 

# 
CONFIG = OSX 

# --- Compilation 
---------------------------------------------------------- 
CC   = cc 
CXX   = c++ 
LD   = c++ 
MAKEDEP  = c++ -MM $(SYS_INC_DIRS) $(INC_DIRS) $(SRCS) >  Makefile.depend 
CPP   = cpp 
LIBTOOL  = glibtool 

LD_FLAGS = 
CFLAGS  = -O2 
DBG_CFLAGS = -g 

SHARED_LIBS = off 
USE_RANLIB = 1  

DEST  = $(REACTOR) 

config: 
    @echo "configured for Mac OSX" 

# --- System  ------------------------------------------------------------------- 
SYS_INC_DIRS  = -I/sw/include 
SYS_LIB_DIRS  = -L/sw/lib 
SYS_LIBS   = 
SYS_DBG_LIBS  = 

# --- VL  ----------------------------------------------------------------------- 
CL_EXT_FLAGS = -DCL_TMPL_INST -DCL_HAS_VSNPRINTF -DCL_POSIX_TIME 
VL_EXT_FLAGS = -DVL_HAS_ABSF -DVL_USE_MEMCPY 

運行make

cd src && /Applications/Xcode.app/Contents/Developer/usr/bin/make REACTOR=.. 
c++ -O2 \ 
      -c LibSVL.cpp -I../include -I/sw/include 
c++ -O2 \ 
      -c Basics.cpp -I../include -I/sw/include 
ar rcu libsvl.a LibSVL.o Basics.o 
mkdir -p ../lib 
mv libsvl.a ../lib 
c++ -DDEBUG -g \ 
      -DVL_DEBUG \ 
      -c LibSVL.cpp -o LibSVL.do -I../include -I/sw/include 
c++ -DDEBUG -g \ 
      -DVL_DEBUG \ 
      -c Basics.cpp -o Basics.do -I../include -I/sw/include 

完全make文件的結果

# 
# Main makefile for SVL distribution 
# 

# NOTE: To build multiple system libraries in AFS, make 'afs-setup' first. 
# This will create the necessary architecture-dependent lib directories, 
# and ensure that the config header goes there. 

REACTOR=. 

all: $(REACTOR)/makefiles/config.mf 
    cd src && $(MAKE) REACTOR=.. 

SHELL   = /bin/sh 
DEST   = /usr/local 
CONFIG_DEST  = $(DEST)/include 

clean: 
    @-echo 'Making clean...' 
    @-cd src && $(MAKE) REACTOR=.. clean 
    @-rm -f lib/lib* 

install: install-headers install-libs 

install-headers: 
    @-echo "installing into $(DEST)/include/svl $(DEST)/doc" 
    @-chmod a+r include/svl/* doc/* 
    @-umask 022 \ 
     && mkdir -p $(DEST)/doc $(DEST)/include/svl 
    @-umask 022 \ 
     && cp doc/* $(DEST)/doc \ 
     && cp include/svl/* $(DEST)/include/svl 
    @-echo "done." 

install-libs: 
    @-echo "installing into $(DEST)/lib $(CONFIG_DEST)" 
    @-chmod a+r lib/* include/SVLConfig.h 
    @-umask 022 \ 
     && mkdir -p $(DEST)/lib $(CONFIG_DEST) 
    @-umask 022 \ 
     && cp lib/* $(DEST)/lib \ 
     && cp include/SVLConfig.h $(CONFIG_DEST) 
    @-echo "done." 

# setup for multi-architecture build in afs. 
afs-setup: 
    @-echo "Creating afs multiple-system lib directory" 
    @-rm -r lib; ln -s .arch/@sys/lib lib 
    # ensure the config file goes in the lib directory. 
    @-ln -sf ../lib/svl/SVLConfig.h include/SVLConfig.h 

# if lib is a broken symbolic link, create the necessary .arch directory. 
afs-lib: 
    @-if test ! -d lib; then mkdir -p .arch/`sys`/lib/svl; \ 
     touch .arch/`sys`/lib/svl/SVLConfig.h; fi 

config: afs-lib 
    $(MAKE) config -f makefiles/svl.mf 

# --- setup ----------- 

# auto-generated by make-config-mf 

$(REACTOR)/makefiles/config.mf: 
    @-echo "=== System Configuration ===" 
    @-echo "Select one of the following systems, and then run 'make <system>'." 
    @-echo 
    @-echo " OSX" 
    @-echo " alpha" 
    @-echo " linux_RH" 
    @-echo " sgi-n32" 
    @-echo " sgi-n64" 
    @-echo " sgi-o32" 
    @-echo " solaris-gcc" 
    @-echo " sunos-gcc" 
    @-echo 
    @-echo "After this is done, you can edit makefiles/config.mf to change" 
    @-echo "compiler settings and paths. If you change the build flags, you" 
    @-echo "must run 'make config' to update the headers." 
    @exit 1 

OSX: 
    cp $(REACTOR)/makefiles/config-OSX.mf $(REACTOR)/makefiles/config.mf 
    $(MAKE) config 
alpha: 
    cp $(REACTOR)/makefiles/config-alpha.mf $(REACTOR)/makefiles/config.mf 
    $(MAKE) config 
linux_RH: 
    cp $(REACTOR)/makefiles/config-linux_RH.mf $(REACTOR)/makefiles/config.mf 
    $(MAKE) config 
sgi-n32: 
    cp $(REACTOR)/makefiles/config-sgi-n32.mf $(REACTOR)/makefiles/config.mf 
    $(MAKE) config 
sgi-n64: 
    cp $(REACTOR)/makefiles/config-sgi-n64.mf $(REACTOR)/makefiles/config.mf 
    $(MAKE) config 
sgi-o32: 
    cp $(REACTOR)/makefiles/config-sgi-o32.mf $(REACTOR)/makefiles/config.mf 
    $(MAKE) config 
solaris-gcc: 
    cp $(REACTOR)/makefiles/config-solaris-gcc.mf $(REACTOR)/makefiles/config.mf 
    $(MAKE) config 
sunos-gcc: 
    cp $(REACTOR)/makefiles/config-sunos-gcc.mf $(REACTOR)/makefiles/config.mf 
    $(MAKE) config 
+0

不要重新發布的問題。 [原文](http://stackoverflow.com/questions/34131667/including-an-external-library-in-c-program-using-mac-osx)。 – trojanfoe

回答

0

,你必須執行

sudo make install 
+0

太棒了!這有幫助。 #include包含錯誤,它說 '在包含在vertex.cc中的文件中:10:' '從/usr/local/include/svl/Vec3.h中包含的文件:14:' 但現在我有其他的錯誤,說'錯誤:未知類型名'真',所以類沒有正確鏈接,我猜。我只是在做'g ++ vertex.cc vertex.hh'編譯。我應該在編譯時加入其他一些指令嗎? –