[英]Autotools not linking GLFW properly
I'm trying to set up a project using autotools. 我正在尝试使用自动工具来建立一个项目。 I'm going to need the executable to be linked against GLFW, but I can't get it to work.
我将需要将可执行文件与GLFW链接,但我无法使其正常工作。
configure.ac: configure.ac:
AC_INIT([Test], [0.1], [test@example.com])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CXX
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
Makefile
src/Makefile
])
AC_OUTPUT
PKG_CHECK_MODULES([glfw3],[glfw3])
Makefile.am: Makefile.am:
SUBDIRS = src
src/Makefile.am: src / Makefile.am:
bin_PROGRAMS = testapp
testapp_SOURCES = main.cpp
testapp_CFLAGS = ${glfw3_CFLAGS}
testapp_LDADD = ${glfw3_LIBS}
When I run ./configure, everything works out just fine. 当我运行./configure时,一切正常。 glfw3 is found as expexted.
发现glfw3已扩展。 However, when I try to compile the code using make, it appears that the executable isn't linked properly.
但是,当我尝试使用make编译代码时,似乎可执行文件未正确链接。
make all-recursive
make[1]: Entering directory '/home/dennis/Utveckling/testapp'
Making all in src
make[2]: Entering directory '/home/dennis/Utveckling/testapp/src'
g++ -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.cpp
mv -f .deps/main.Tpo .deps/main.Po
g++ -g -O2 -o testapp main.o
main.o: In function `main':
/home/dennis/Utveckling/testapp/src/main.cpp:6: undefined reference to `glfwInit'
/home/dennis/Utveckling/testapp/src/main.cpp:7: undefined reference to `glfwCreateWindow'
/home/dennis/Utveckling/testapp/src/main.cpp:8: undefined reference to `glfwMakeContextCurrent'
/home/dennis/Utveckling/testapp/src/main.cpp:12: undefined reference to `glClear'
/home/dennis/Utveckling/testapp/src/main.cpp:13: undefined reference to `glfwSwapBuffers'
/home/dennis/Utveckling/testapp/src/main.cpp:14: undefined reference to `glfwPollEvents'
/home/dennis/Utveckling/testapp/src/main.cpp:10: undefined reference to `glfwWindowShouldClose'
collect2: error: ld returned 1 exit status
Makefile:333: recipe for target 'testapp' failed
make[2]: *** [testapp] Error 1
make[2]: Leaving directory '/home/dennis/Utveckling/testapp/src'
Makefile:353: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/dennis/Utveckling/testapp'
Makefile:294: recipe for target 'all' failed
make: *** [all] Error 2
What am I doing wrong? 我究竟做错了什么? The code is a copy and paste from http://www.glfw.org/documentation.html
该代码是从http://www.glfw.org/documentation.html复制并粘贴的
You should move PKG_CHECK_MODULE
before AC_OUTPUT
. 您应该在
AC_OUTPUT
之前移动PKG_CHECK_MODULE
。 The configure.ac
is executed top-down, so you're subsituting the values into your Makefile.in
before you calculate it. configure.ac
是自上而下执行的,因此您需要在计算值之前将其替换为Makefile.in
。
Also a note out of style, in Makefile.am
you should use $()
form rather than ${}
. 另外请注意,在
Makefile.am
,应使用$()
形式而不是${}
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.