【问题标题】:Error undefined reference to symbol 'FCGX_InitRequest' on compiler c++ FreeBSD编译器 c++ FreeBSD 上对符号“FCGX_InitRequest”的未定义引用错误
【发布时间】:2017-10-09 20:45:27
【问题描述】:

我正在尝试编译 C++ 代码,但发生错误:

对符号'FCGX_InitRequest'的未定义引用

我使用的是freebsd,并且已经安装了lfcgi库。

我用来执行此操作的代码:

g++49 echo-cpp.cpp -lfcgi++ -o hello_world

还有我的代码:

#include "fcgio.h"

int main() {
    FCGX_Request request;

    FCGX_Init();

    FCGX_InitRequest(&request, 0, 0);

    while ( FCGX_Accept_r(&request) == 0 ) {
        fcgi_streambuf cout_fcgi_streambuf(request.out);

        std::cout.rdbuf(&cout_fcgi_streambuf);

        std::cout << "Content-type: text/html\r\n"
                     "\r\n"
                     "<h1>Hello world :)</h1>";
    }

    return 0;
}

谢谢!

---- 编辑----

我改了编译命令

g++49 echo-cpp.cpp -lfcgi++ -lfcgi -o hello_world

而且错误已经改变:

//usr/local/lib/libfcgi++.so: undefined reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char> >::xsputn(char const*, long)'                                                 
//usr/local/lib/libfcgi++.so: undefined reference to `std::__1::basic_ostream<char, std::__1::char_traits<char> >::~basic_ostream()'                                                            
//usr/local/lib/libfcgi++.so: undefined reference to `virtual thunk to std::__1::basic_ostream<char, std::__1::char_traits<char> >::~basic_ostream()'                                           
//usr/local/lib/libfcgi++.so: undefined reference to `std::__1::basic_ios<char, std::__1::char_traits<char> >::~basic_ios()'                                                                    
//usr/local/lib/libfcgi++.so: undefined reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char> >::~basic_streambuf()'                                                        
//usr/local/lib/libfcgi++.so: undefined reference to `std::__1::basic_ostream<char, std::__1::char_traits<char> >::~basic_ostream()'                                                            
//usr/local/lib/libfcgi++.so: undefined reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char> >::imbue(std::__1::locale const&)'                                            
//usr/local/lib/libfcgi++.so: undefined reference to `std::__1::basic_istream<char, std::__1::char_traits<char> >::~basic_istream()'                                                            
//usr/local/lib/libfcgi++.so: undefined reference to `std::__1::ios_base::init(void*)'                                                                                                          
//usr/local/lib/libfcgi++.so: undefined reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char> >::showmanyc()'                                                               
//usr/local/lib/libfcgi++.so: undefined reference to `virtual thunk to std::__1::basic_istream<char, std::__1::char_traits<char> >::~basic_istream()'                                           
//usr/local/lib/libfcgi++.so: undefined reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char> >::seekpos(std::__1::fpos<__mbstate_t>, unsigned int)'                        
//usr/local/lib/libfcgi++.so: undefined reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char> >::basic_streambuf()'                                                         
//usr/local/lib/libfcgi++.so: undefined reference to `typeinfo for std::__1::basic_streambuf<char, std::__1::char_traits<char> >'
//usr/local/lib/libfcgi++.so: undefined reference to `std::__1::basic_istream<char, std::__1::char_traits<char> >::~basic_istream()'
//usr/local/lib/libfcgi++.so: undefined reference to `std::__1::basic_istream<char, std::__1::char_traits<char> >::~basic_istream()'
//usr/local/lib/libfcgi++.so: undefined reference to `typeinfo for std::__1::basic_istream<char, std::__1::char_traits<char> >'
//usr/local/lib/libfcgi++.so: undefined reference to `virtual thunk to std::__1::basic_ostream<char, std::__1::char_traits<char> >::~basic_ostream()'
//usr/local/lib/libfcgi++.so: undefined reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char> >::seekoff(long long, std::__1::ios_base::seekdir, unsigned int)'
//usr/local/lib/libfcgi++.so: undefined reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char> >::xsgetn(char*, long)'
//usr/local/lib/libfcgi++.so: undefined reference to `typeinfo for std::__1::basic_ostream<char, std::__1::char_traits<char> >'
//usr/local/lib/libfcgi++.so: undefined reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char> >::pbackfail(int)'
//usr/local/lib/libfcgi++.so: undefined reference to `std::__1::basic_ostream<char, std::__1::char_traits<char> >::~basic_ostream()'
//usr/local/lib/libfcgi++.so: undefined reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char> >::setbuf(char*, long)'
//usr/local/lib/libfcgi++.so: undefined reference to `virtual thunk to std::__1::basic_istream<char, std::__1::char_traits<char> >::~basic_istream()'

【问题讨论】:

    标签: c++ compiler-errors g++ fastcgi freebsd


    【解决方案1】:

    函数FCGX_InitRequest是C库libfcgi中定义的C语言函数,不是 在 C++ 库libfcgi++ 中。您需要链接两者,并且 C++ 库依赖于 C 库。所以 将链接中的-lfcgi++ 替换为-lfcgi++ -lfcgi

    【讨论】:

      猜你喜欢
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 2011-12-10
      相关资源
      最近更新 更多