我在尝试将自动工具用于一个简单的人为项目时遇到问题,任务很简单,在 Mac OSX 上使用 Objective-C,在 Windows (mingw) 上使用 C++ - 中间有一些 C
胶水。
该项目的结构如下(减去所有自动生成的文件):
./aclocal.m4
./configure
./configure.ac
./Makefile.am
./src/darwin/greet.m
./src/greet.h
./src/main.cpp
./src/Makefile.am
./src/mingw32/greet.cpp
关键文件的内容位于 github要点。 (不想在这里发送垃圾邮件)
我在更改之间使用以下命令:
$ autoreconf -vis && ./configure && make
我收到的错误是完整输出(这里是另一个要点):
....
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
我对自动工具非常陌生,并且在 IRC 上一些好人的帮助下已经取得了很大的进步,但我认为我正在制作一个概念这里犯了一个错误,真的希望我犯的是一个简单的错误。
我从文档中了解到,EXTRA_progname_SOURCES
应包含所有可能的文件,并且设置的条件应能够选择正确的文件。
令人担忧的是,我认为我的 makefile 没有被重新制作,因为即使我更改 src/Makefile.am 中的行以明确包含我的平台(即 Max OS X Darwin)的源代码,大多数的时间)——输出保持完全相同。
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 output remains completely the same.
发布评论
评论(2)
g++ -g -O2 -ogreetings main.o
此行尝试从 main.o 构建问候语可执行文件。如果在其他文件中定义了greet()函数,例如greet.cpp,则应为:
++ -g -O2 -ogreetings main.ogreet.o
可能是Makefile.am中的这一行
greetings_SOURCES = main。 cppgreet.h
应该是这样的:
greetings_SOURCES = main.cppgreet.cpp
在Makefile.am 中你有:
这是没有正确执行的地方。你需要检查一下。
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:
This is the place which is not executed properly. You need to check it.
我发现您在要点中指的是
greet.mm
,但在问题中指的是greet.m
。 Automake 似乎不原生支持 Objective-C++代码。对于 Objective-C 代码,您需要在configure.ac
中包含AC_PROG_OBJC
。如果您确实指的是 Objective-C++ 代码,则需要执行以下操作 通过后缀规则。I see that you're referring to
greet.mm
in the gist, butgreet.m
in the question. Automake does not appear to natively support Objective-C++ code. For Objective-C code, you need to haveAC_PROG_OBJC
in yourconfigure.ac
. If you really meant Objective-C++ code, you'll need to do this via a suffix rule.