在编译器 c++ FreeBSD 上错误未定义对符号 'FCGX_InitRequest' 的引用
Error undefined reference to symbol 'FCGX_InitRequest' on compiler c++ FreeBSD
我正在尝试编译 C++ 代码,但出现错误:
undefined reference to symbol '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()'
函数FCGX_InitRequest
是C库libfcgi
中定义的C语言函数,不是
在 C++ 库中 libfcgi++
。你需要 link 两者,C++ 库依赖于 C 库。所以
将 -lfcgi++
替换为 -lfcgi++ -lfcgi
在您的 linkage.
我正在尝试编译 C++ 代码,但出现错误:
undefined reference to symbol '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()'
函数FCGX_InitRequest
是C库libfcgi
中定义的C语言函数,不是
在 C++ 库中 libfcgi++
。你需要 link 两者,C++ 库依赖于 C 库。所以
将 -lfcgi++
替换为 -lfcgi++ -lfcgi
在您的 linkage.