我正在尝试编译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()'
答案 0 :(得分:0)
函数FCGX_InitRequest
是C库libfcgi
中定义的C语言函数,而不是
在C ++库libfcgi++
中。您需要链接两者,C ++库依赖于C库。所以
在您的链接中将-lfcgi++
替换为-lfcgi++ -lfcgi
。