如何在C ++中包含外部库?

时间:2015-12-07 13:53:46

标签: c++ macos

我正在尝试将external library called SVL (simple vector library)包含在c ++中。我遇到很多麻烦。我使用的是Mac OSX,库的README只有Windows的教程。

我做了

 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

1 个答案:

答案 0 :(得分:0)

你必须执行

sudo make install