如何在较高版本的gcc程序中使用较低版本的gcc编译的.so?

时间:2019-03-28 10:04:27

标签: c++ c gcc g++

我从下面的GCC版本5.4.0制作.so是.so的代码。

#include <iostream>
#ifdef __cplusplus
extern "C"
{
#endif
        void print();
#ifdef __cplusplus
}
#endif
using namespace std;
void print()
{
    cout<<"Hello"<<endl;
}

g ++ ab.cpp -fPIC -shared -o libab.so

我正在尝试在我的c程序中使用libab.so。但是gcc版本不同

/ root / test / newgcc / usr / bin / x86_64-vmk-linux-gnu-gcc -v

目标:x86_64-vmk-linux-gnu 配置为:/ build / mts / release / bora-12413527 / cayman_gcc / gcc / src / configure --build = x86_64-linux --host = x86_64-linux --target = x86_64-vmk-linux-gnu --prefix = / usr --with-sysroot = / dev / null --with-build-sysroot = / build / mts / release / bora-12413527 / cayman_gcc / build / release / lin64 / gcc / build / x86_64-vmk-linux-gnu / sysroot --enable-languages = c,c ++ --disable-sjlj-exceptions --enable-frame-pointer 螺纹型号:posix gcc版本6.4.0(GCC)

#include <stdio.h>
#ifdef __cplusplus
extern "C"
{
#endif
    void print();    
#ifdef __cplusplus
}
#endif
int main()
{
    print();
    return 0;
}

我遇到了错误

/root/test/newgcc/usr/bin/../lib/gcc/x86_64-vmk-linux-gnu/6.4.0/../../../../x86_64-vmk-linux-gnu/bin/ld: warning: libstdc++.so.6, needed by ./libab.so, not found (try using -rpath or -rpath-link)
./libab.so: undefined reference to `std::ios_base::Init::~Init()@GLIBCXX_3.4'
./libab.so: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)@GLIBCXX_3.4'
./libab.so: undefined reference to `std::ios_base::Init::Init()@GLIBCXX_3.4'
./libab.so: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)@GLIBCXX_3.4'
./libab.so: undefined reference to `std::cout@GLIBCXX_3.4'
./libab.so: undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))@GLIBCXX_3.4'
collect2: error: ld returned 1 exit status

有什么方法可以使用gcc版本6编译代码,而.so是在gcc版本5上创建的?

0 个答案:

没有答案