c++ - 为 ubuntu 写一个 cygwin makefile

标签 c++ compiler-construction g++ cygwin

我正在尝试编译开源 AAM 库。我在 Visual Studio 中尝试过,虽然它编译了,但它有一个运行时错误。现在我正在尝试使用 G++ 在 Ubuntu 11.04 中编译它。唯一提供的 makefile 是一个 cygwin makefile。我正在尝试使用它在 Ubuntu 中进行编译。 (我在下面包含了 makefile)。我遇到的问题接近底部:

libaamlibrary.dll.a: $(OBJS)
        g++ -fPIC -shared $(OBJS) $(LIBS) -o cygaamlibrary-2.dll -Wl,--enable-auto-image-base -Xlinker --out-implib -Xlinker libaamlibrary.dll.a

“--enable-auto-image-base”不是可识别的选项。我正在尝试将这 3 行重写为一种形式,它做同样的事情但在 Ubuntu 中工作,但我很挣扎,因为我真的不明白这些行在做什么(例如,我不明白 Xlinker 以及它如何应该使用)。任何建议将不胜感激......这是完整的 makefile 以供引用:

CPPFLAGS = -I. -I/home/andrew/MscProject/OpenCV-2.3.0/include/opencv -O2 -Wall -g -MD -fPIC
PROGRAMS = libaamlibrary.dll.a  libaamlibrary.a fit build 
LIBS = -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann  
OBJS = AAM_Util.o VJfacedetect.o AAM_Shape.o AAM_CAM.o AAM_PAW.o AAM_PDM.o AAM_TDM.o AAM_MovieAVI.o AAM_Basic.o AAM_IC.o

all: $(PROGRAMS)

AAM_Util.o: AAM_Util.cpp AAM_Util.h 
    g++  $(CPPFLAGS)  -c -o AAM_Util.o AAM_Util.cpp

AAM_Shape.o: AAM_Shape.cpp AAM_Shape.h
    g++  $(CPPFLAGS)  -c -o AAM_Shape.o AAM_Shape.cpp

AAM_TDM.o: AAM_TDM.cpp AAM_TDM.h 
    g++  $(CPPFLAGS)  -c -o AAM_TDM.o AAM_TDM.cpp

AAM_PDM.o: AAM_PDM.cpp AAM_PDM.h 
    g++  $(CPPFLAGS)  -c -o AAM_PDM.o AAM_PDM.cpp

AAM_PAW.o: AAM_PAW.cpp AAM_PAW.h
    g++  $(CPPFLAGS)  -c -o AAM_PAW.o AAM_PAW.cpp

AAM_CAM.o: AAM_CAM.cpp AAM_CAM.h 
    g++  $(CPPFLAGS)  -c -o AAM_CAM.o AAM_CAM.cpp

VJfacedetect.o: VJfacedetect.cpp VJfacedetect.h 
    g++  $(CPPFLAGS)  -c -o VJfacedetect.o VJfacedetect.cpp

AAM_MovieAVI.o: AAM_MovieAVI.cpp AAM_MovieAVI.h
    g++  $(CPPFLAGS)  -c -o AAM_MovieAVI.o AAM_MovieAVI.cpp

AAM_Basic.o: AAM_Basic.cpp AAM_Basic.h
    g++  $(CPPFLAGS)  -c -o AAM_Basic.o AAM_Basic.cpp

AAM_IC.o: AAM_IC.cpp AAM_IC.h 
    g++  $(CPPFLAGS)  -c -o AAM_IC.o AAM_IC.cpp

demo_build.o: train.cpp
    g++  $(CPPFLAGS)  -c -o demo_build.o train.cpp

demo_fit.o: fit.cpp
    g++  $(CPPFLAGS)  -c -o demo_fit.o fit.cpp

libaamlibrary.a: $(OBJS) 
    ar cru libaamlibrary.a $(OBJS)
    ranlib libaamlibrary.a

libaamlibrary.dll.a: $(OBJS)
    g++ -fPIC -shared $(OBJS) $(LIBS) -o cygaamlibrary-2.dll -Wl,--enable-auto-image-base -Xlinker --out-implib -Xlinker libaamlibrary.dll.a

fit: demo_fit.o
    g++ -o fit demo_fit.o libaamlibrary.dll.a $(LIBS) 

build: demo_build.o
    g++ -o build demo_build.o libaamlibrary.dll.a $(LIBS)

clean:
    rm -f *.o $(PROGRAMS)

最佳答案

我同意你不应该使用 .dll.a 或 .dll 扩展名(我相信 .a 和 .so 是合适的),但似乎你不能没有 libaamlibrary[.dll].a。

由于“--enable-auto-image-base”以 -Wl 为前缀,这使其成为链接器 (ld) 选项。

我搜索了“man ld”并想到了这个:

--enable-auto-image-base Automatically choose the image base for DLLs, unless one is specified using the "--image-base" argument. By using a hash generated from the dllname to create unique image bases for each DLL, in-memory collisions and relocations which can delay program execution are avoided. [This option is specific to the i386 PE targeted port of the linker]

您的平台是什么?据我所知,它不适用于非 i386 架构,也许不需要?那么您可以尝试在没有它的情况下进行编译吗?

顺便说一下,我推荐使用优秀的 Autotools 包 (automake/autoconf/libtool)。

关于 --out-implib,它在 amd64 上也不可用。

--out-implib file The linker will create the file file which will contain an import lib corresponding to the DLL the linker is generating. This import lib (which should be called ".dll.a" or ".a" may be used to link clients against the generated DLL; this behaviour makes it possible to skip a separate "dlltool" import library creation step. [This option is specific to the i386 PE targeted port of the linker]

抱歉,我不知道导入库是什么。

关于c++ - 为 ubuntu 写一个 cygwin makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6479693/

相关文章:

C/C++ 到 MATLAB 编译器/转换器

c++ - stringstream 不接受空格?

c++ - CodeBlocks为32位计算机编译程序

c++ - 使用 std::cin 忽略/跳过标记

c++ - 在 C++ 中模拟系统级的键盘输入

c++ - 如何从外部代码和 Makefile 启动 CodeBlocks 项目?

java - 我收到此警告 : com. sun.org.apache.xml.internal.serialize.OutputFormat is Sun proprietary API and may be removed in a future release

c++ -/usr/bin/ld 仅在编译期间找不到 <library>

C++错误将参数重新发送到模板函数(矩阵参数)

c++ - 临时对象存储在哪里?