簡體   English   中英

自動工具無法正確鏈接GLFW

[英]Autotools not linking GLFW properly

我正在嘗試使用自動工具來建立一個項目。 我將需要將可執行文件與GLFW鏈接,但我無法使其正常工作。

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:

SUBDIRS = src

src / Makefile.am:

bin_PROGRAMS = testapp
testapp_SOURCES = main.cpp
testapp_CFLAGS = ${glfw3_CFLAGS}
testapp_LDADD = ${glfw3_LIBS}

當我運行./configure時,一切正常。 發現glfw3已擴展。 但是,當我嘗試使用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

我究竟做錯了什么? 該代碼是從http://www.glfw.org/documentation.html復制並粘貼的

您應該在AC_OUTPUT之前移動PKG_CHECK_MODULE configure.ac是自上而下執行的,因此您需要在計算值之前將其替換為Makefile.in

另外請注意,在Makefile.am ,應使用$()形式而不是${}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM