gpt4 book ai didi

c++ - 在 autotools 项目中添加 C++ 支持?

转载 作者:太空宇宙 更新时间:2023-11-04 04:04:26 24 4
gpt4 key购买 nike

我现在正在编写一个需要在我的 C 代码中使用 C++ 的应用程序。我的问题是我无法通过 C++ 代码进行编译。

我有两个源文件夹,cpp(只包含一个c源文件)和src(只包含一个c++源文件)。

我的configure.in就是这样,很简单

AC_PREREQ([2.68])
AC_INIT([tste], [1.0], [ee@b.com])
AC_PROG_CXX
AC_PROG_CC
AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE()
AC_CONFIG_FILES([Makefile cpp/Makefile src/Makefile] )
AC_OUTPUT

./Makefile.am:

SUBDIRS= src cpp

./cpp/Makefile.am:

bin_PROGRAMS=main
main_SOURCES=main.c

./src/Makefile.am:

bin_PROGRAMS=test
test_SOURCES=testcpp.cpp

当我使用make编译我的项目时,出现错误:

Making all in src
make[1]: Entering directory `/home/hujin/Desktop/test/src'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/hujin/Desktop/test/src'
Making all in cpp
make[1]: Entering directory `/home/hujin/Desktop/test/cpp'
make[1]: *** No rule to make target `main.o', needed by `main'. Stop.
make[1]: Leaving directory `/home/hujin/Desktop/test/cpp'
make: *** [all-recursive] Error 1

最佳答案

如果我在你的皮肤上,我不会将项目拆分为 submakefile,因为它都指向一个目标(“tste”)。

您最好将所有源文件放在根目录 Makefile.am 中(您可以从中生成多个输出):

# ./Makefile.am:

bin_PROGRAMS=main test

main_SOURCES=cpp/main.c
test_SOURCES=src/testcpp.cpp

将您的 configure.ac 更改为如下内容:

# configure.ac
AC_PREREQ([2.68])

AC_INIT([tste], [1.0], [ee@b.com])
AM_INIT_AUTOMAKE

AC_CONFIG_SRCDIR([src/testcpp.cpp])

AC_PROG_CXX
AC_PROG_CC

AC_CONFIG_FILES([Makefile])
AC_OUTPUT

然后运行: aclocal && autoconf && automake 。/配置 制作

这里有一些不错的链接:

关于c++ - 在 autotools 项目中添加 C++ 支持?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7860536/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com