Compiling on Windows and Mac with Autotool
I have a problem trying to use autotools for a simple contrived project, the task is simple, use Objective-C on Mac OSX, and C++ on Windows (mingw) - with some C
glue in the middle.
The project is structured like so (minus all the automatically generated files):
./aclocal.m4
./configure
./configure.ac
./Makefile.am
./src/darwin/greet.m
./src/greet.h
./src/main.cpp
./src/Makefile.am
./src/mingw32/greet.cpp
The contents of the key files are here on github in a gist. (didn't want to spam here)
I'm using the following command between changes:
$ autoreconf -vis && ./configure && make
The error I receive is full output (here in another gist):
....
Making all in src
g++ -g -O2 -o greetings main.o
Undefined symbols:
"greet()", referenced from:
_main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[1]: *** [greetings] Error 1
make: *** [all-recursive] Error 1
I'm very new to autotools, and have come a long way with the help of a couple of good people on IRC, but I think I'm making a conceptual mistake here, really hope there's a simple mistake I am making.
It was my understanding from the docs that EXTRA_progname_SOURCES
should contain all possible files, and that the conditionals which are setup should work to select the correct ones.
Alarmingly, I don't think my makefiles are being remade, because even when I change the line in src/Makefile.am
to include the sources explicitly for my platform (which is Max OS X Darwin, most of the time) -- the o开发者_开发知识库utput remains completely the same.
I see that you're referring to greet.mm
in the gist, but greet.m
in the question. Automake does not appear to natively support Objective-C++ code. For Objective-C code, you need to have AC_PROG_OBJC
in your configure.ac
. If you really meant Objective-C++ code, you'll need to do this via a suffix rule.
g++ -g -O2 -o greetings main.o
This line tries to build greetings executable from main.o. If greet() function is defined in some other file, for example, greet.cpp, it should be:
++ -g -O2 -o greetings main.o greet.o
Possibly, this line from Makefile.am
greetings_SOURCES = main.cpp greet.h
should be something like this:
greetings_SOURCES = main.cpp greet.cpp
In Makefile.am you have:
if OS_DARWIN greetings_SOURCES += darwin/greet.mm endif if OS_MINGW32 greetings_SOURCES += mingw32/greet.cpp endif
This is the place which is not executed properly. You need to check it.
精彩评论