使用autotools的未定义引用

时间:2017-11-27 22:04:41

标签: c++ gcc autotools

我现在正在努力解决这些未定义的引用,我在下面通过在我的机器上使用autotools进行了描述。

我不确定为什么我有未定义的refs,但我怀疑有一些与autotools有关的东西,也许c ++ 17没有与autotools完全集成,我的设置很糟糕或者......我出去了想法。

我检查了语法万亿次,将模板定义仅移动到标题,将参数计数更改为函数,重新排列Makefile ..等等..仍然没有。

也许你可以帮助我?

configure.ac

AC_INIT([CRYPTO], [0.1], [iamhidingmymail@gmail.com])
AM_INIT_AUTOMAKE 

AC_PROG_RANLIB
AC_PROG_CXX
AC_LANG(C++)
AX_CHECK_COMPILE_FLAG([-std=c++17], [
                        CXXFLAGS="$CXXFLAGS -std=c++17"])
AC_CONFIG_FILES([ fsio/Makefile logger/Makefile  rsa/Makefile primes/Makefile Makefile])
AC_OUTPUT

topdir - > Makefile.am

AUTOMAKE_OPTIONS = foreign
SUBDIRS = logger fsio  primes rsa 

AM_CPPFLAGS = -I$(top_srcdir) -Wall -std=c++17

bin_PROGRAMS = crypto.out

crypto_out_SOURCES = bigInt.cpp  Source.cpp  

crypto_out_LDADD = -lpthread fsio/libFsio.a logger/libLogger.a rsa/libRSA.a primes/libPrimes.a 

fsio / Makefile.am

noinst_LIBRARIES = libFsio.a

libFsio_a_SOURCES = fsio.cpp

libFsio_a_CPPFLAGS = -I$(top_srcdir) -Wall -std=c++17

记录器/ Makefile.am

noinst_LIBRARIES = libLogger.a

libLogger_a_SOURCES = loga.cpp

libLogger_a_CPPFLAGS = -I$(top_srcdir) -Wall -std=c++17

未定义的参考1:

Source.cpp:17: undefined reference to `void logger::loga::I<char const*, char const*, char const*>(char const*, char const*, char const*)'

而Source.cpp:17是:

logger::loga l("testlog.log");
    l.I("Test", "test ","!");//line 17

并定义为:

template<typename ...message>
    void loga::I(message ...m){
        //(this is fold expression)
        //code
    }

未定义参考2:

logger/libLogger.a(libLogger_a-loga.o): In function `logger::loga::loga(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
<path>/logger/loga.cpp:7: undefined reference to `fsio::file::file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::_Ios_Openmode)'
<path>/logger/loga.cpp:7: undefined reference to `fsio::file::operator=(fsio::file const&)'

而loga.cpp:7是:

loga::loga(std::string filename){
        Logger = std::move(fsio::file(filename));//line 7
    }

记录器定义为:

::fsio::file Logger;

在fsio.h中

文件构造函数和operator =的定义可以在

下面找到
//in header file constructor is declared as
(std::string& filename, std::fstream::openmode it = 
    (std::ios::app|std::ios::out|std::ios::in));

file::file(std::string& filename , std::ios_base::openmode om ){
        //code
        //code
    }

file& file::operator=(const file& f){
        //code
        return *this;
    }

二进制文件编译为:

g++  -g -O2 -std=c++17   -o crypto.out bigInt.o Source.o -lpthread fsio/libFsio.a logger/libLogger.a rsa/libRSA.a primes/libPrimes.a

我为运行configure,make等制作了自定义脚本。它是:

./构建

#!/bin/bash
set -e

aclocal
autoconf
automake --add-missing
./configure
echo
make -j4

echo "building done, running application:"
./crypto.out
echo "done!"

FYI

 Ubuntu 17.10

    uname -a

    Linux nikola 4.13.0-041300-generic #201709031731 SMP Sun Sep 3 21:33:09 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

    automake --version

    automake (GNU automake) 1.15

    g++ -v

    gcc version 7.2.0 (Ubuntu 7.2.0-8ubuntu3)

如果您觉得代码很短,请访问我的github

https://github.com/NikolaLozanovski/crypto/tree/logger

branch:logger

谢谢!

1 个答案:

答案 0 :(得分:0)

对于 UR1 ,我在标头文件中定义模板函数,以前模板函数在标头中声明但在源中定义。这就是诀窍

对于 UR2 包含定义这些函数的静态库,并在相应的 makefile <中使用_ LIBADD 指令/ strong>即可。编译器不知道在哪里找到这些函数的符号。现在它知道了:))