Linux makefile 中未定义的引用

发布于 2024-12-04 15:20:09 字数 1180 浏览 3 评论 0原文

我想在 Linux 下构建我的应用程序,但我无法让我的 makefile 来制作它。
问题是我想要链接的静态库。我收到很多“未定义的引用”错误消息,例如:

undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'

undefined reference to `cgicc::Cgicc::Cgicc(cgicc::CgiInput*)'

这是我的 makefile:

CXX = gcc

INCL_CGICC = ../cgicc-3.2.9
INCL_OPENSSL = ../openssl-1.0.0e/include
INCL_LOG4CPLUS = ../log4cplus-1.0.4/include
INCL_BOOST = ../boost_1_46_1
INCLUDES = -I$(INCL_CGICC) -I$(INCL_OPENSSL) -I$(INCL_LOG4CPLUS) -I$(INCL_BOOST)

CXXFLAGS = -Wall -D_LINUX -DVERSNUM=2 -DVERSMAJOR=0 -DVERSMINOR=0 $(INCLUDES)

TARGET = myapp
OBJS = Main.o 

all: $(TARGET)
strip -s $<
mv -f $< release 

$(TARGET): $(OBJS)
$(CXX) -static -o $@ $(OBJS) \
            ../cgicc-3.2.9/cgicc/.libs/libcgicc.a \
            ../openssl-1.0.0e/libssl.a \
            ../openssl-1.0.0e/libcrypto.a \
            ../log4cplus-1.0.4/src/.libs/liblog4cplus.a \
            -ldl -lpthread

%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $<

问题是我不知道 makefile。我只是复制了一个现有的并尝试对其进行调整。似乎不起作用,而且我找不到包含静态库的示例 makefile。

I want to build my application under linux but i can't get my makefile to make it.
the problems are the static libraries I wan to link with. I get a lot of "undefined reference to" error messages like:

undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'

or

undefined reference to `cgicc::Cgicc::Cgicc(cgicc::CgiInput*)'

Here is my makefile:

CXX = gcc

INCL_CGICC = ../cgicc-3.2.9
INCL_OPENSSL = ../openssl-1.0.0e/include
INCL_LOG4CPLUS = ../log4cplus-1.0.4/include
INCL_BOOST = ../boost_1_46_1
INCLUDES = -I$(INCL_CGICC) -I$(INCL_OPENSSL) -I$(INCL_LOG4CPLUS) -I$(INCL_BOOST)

CXXFLAGS = -Wall -D_LINUX -DVERSNUM=2 -DVERSMAJOR=0 -DVERSMINOR=0 $(INCLUDES)

TARGET = myapp
OBJS = Main.o 

all: $(TARGET)
strip -s 
lt;
mv -f 
lt; release 

$(TARGET): $(OBJS)
$(CXX) -static -o $@ $(OBJS) \
            ../cgicc-3.2.9/cgicc/.libs/libcgicc.a \
            ../openssl-1.0.0e/libssl.a \
            ../openssl-1.0.0e/libcrypto.a \
            ../log4cplus-1.0.4/src/.libs/liblog4cplus.a \
            -ldl -lpthread

%.o: %.cpp
$(CXX) $(CXXFLAGS) -c 
lt;

The problem is that I have no idea of makefiles. I just copied an existing one and tried to adjust it. Didn't seem to work, and I can't find an example makefile that includes static libraries.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最偏执的依靠 2024-12-11 15:20:09

CXX = gcc

您正在链接 gcc,而不是 g++,因此 -lstdc++ 不会被链接到默认。
请注意,使用 gcc 编译 C++ 源代码效果很好,因为在这种情况下会隐式调用 g++。

CXX = gcc

You're linking with gcc, rather than g++, so -lstdc++ is not linked in by default.
Note that using gcc to compile C++ sources work just fine, since g++ is called implicitly in that case.

没有你我更好 2024-12-11 15:20:09

如果您对编写 Makefile 毫无头绪,也许您应该看看一些 Makefile 生成器,例如 autotools、cmake 等。在我看来,这些生成器更容易使用,而且一旦您掌握了它们的使用,它们的功能就会强大得多。

If you have no clue about writing Makefiles, perhaps you should have a look at some of the Makefile generators, e.g. autotools, cmake etc. These are much easier to use in my opinion, and, once you master their use, much more powerful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文