开发者

writing a cygwin makefile for ubuntu

I am trying to compile the open-source AAM-library. I have tried in Visual Studio, and although it compiled, it had a run-time error. Now I'm trying to compile it in Ubuntu 11.04 using G++. The only makefile provided is a cygwin makefile. I am trying to use this to compile in Ubuntu. (I have included the makefile below). The problem I am having is near the bottom in the lines:

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" is not a recognised option. I am trying to rewrite these 3 lines to a form that does the same thing but works in Ubuntu, but I am struggling, because I don't really understand what the lines are doing (e.g., I don't understand Xlinker and how it should be used). Any advice would be much appreciated... Here is the full makefile for reference:

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)


I agree that you should not use a .dll.a or .dll extension (I believe .a and .so are appropriate), but it seems you can't do without libaamlibrary[.dll].a.

Since '--enable-auto-image-base' is prefixed with -Wl, this makes it a linker (ld) option.

I searched 'man ld' and came up with this:

--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]

What is your platform? It is not available to non i386 architectures as I understand, and maybe not needed? So can you try compiling without it?

By the way I recommend using the excellent Autotools package (automake/autoconf/libtool).

Regarding --out-implib it is also not available on 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]

Sorry but I don't know what an import lib is.


Practical approach: first try building without all the .dll and .dll.a stuff; just remove the lines that refer to such targets.

It seems .dll.a files are static archives containing position-independent code (PIC), which are necessary in advanced linking scenarios, i.e. if you're developing shared libraries yourself. (Even if you want such a thing, you shouldn't call it .dll.a on Linux.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜