Reputation: 25
I'm trying to compile a C++ code, but a error happen:
undefined reference to symbol 'FCGX_InitRequest'
I'm using freebsd, and I already installed the lfcgi library.
The code what i using to do this:
g++49 echo-cpp.cpp -lfcgi++ -o hello_world
And my code:
#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;
}
thanks!
---- EDIT ----
I changed the command to compile
g++49 echo-cpp.cpp -lfcgi++ -lfcgi -o hello_world
And the error has changed:
//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()'
Upvotes: 0
Views: 699
Reputation: 61317
The function FCGX_InitRequest
is a C language function defined in the C library libfcgi
, not
in the C++ library libfcgi++
. You need to link both, and the C++ library depends on the C library. So
replace -lfcgi++
with -lfcgi++ -lfcgi
in your linkage.
Upvotes: 1