Hi!
I'm having some trouble with doing simple I/O actions in the clntsrv example (/src/l4/pkg/examples/clntsrv). I want the client to enter minuend and subtrahend himself, so I've added the following code to client.cc:
printf("Please enter minuend and subtrahend: \n"); l4_uint32_t val1, val2; std::cin >> val1 >> val2;
iostream is included at the beginning of the file.
However, the linker has some serious problems:
==> Linking ex_clntsrv-client client.o: In function `main':
/home/hnr/l4re-core-2014022818/src/l4/pkg/examples/clntsrv/client.cc:60: undefined reference to `std::cin'
/home/hnr/l4re-core-2014022818/src/l4/pkg/examples/clntsrv/client.cc:60: undefined reference to `std::istream::operator>>(int&)'
/home/hnr/l4re-core-2014022818/src/l4/pkg/examples/clntsrv/client.cc:60: undefined reference to `std::istream::operator>>(int&)'
client.o: In function `__static_initialization_and_destruction_0': /home/hnr/l4reb/include/contrib/libstdc++-v3/iostream:72: undefined
reference to `std::ios_base::Init::Init()'
/home/hnr/l4reb/include/contrib/libstdc++-v3/iostream:72: undefined
reference to `std::ios_base::Init::~Init()'
make[1]: *** [ex_clntsrv-client] Error 1 make: *** [/home/hnr/l4reb/pkg/examples/clntsrv/OBJ-x86_586-l4f] Error 2
I did not change the Makefile, so g++ is used for compiling (and not gcc). I've added
CXX_FLAGS = -lstdc++
but that doesn't help.
I'm using update-alternatives to have different versions of g++ installed simultaneously. Currently, the link points to g++-4.7. But using g++-4.4 does not solve the problem either.
Thanks in advance for support!
Hi Valentin,
On 2014-05-17 13:00, Valentin Hauner wrote:
I did not change the Makefile, so g++ is used for compiling (and not gcc). I've added
CXX_FLAGS = -lstdc++
but that doesn't help.
The standard way for the l4re build system to link against certain libraries ist to put them in the REQUIRED_LIBS list.
So just change
REQUIRES_LIBS = cxx_libc_io cxx_io
to
REQUIRES_LIBS = cxx_libc_io cxx_io libstdc++
And it compiles fine. Do not forget to also link against libc_be_file_stdin (in the same way as above) if you want to have keyboard interactions.
Best regards
- Marcus Haehnel
Am 17.05.2014 17:47, schrieb Marcus Hähnel:
Hi Valentin,
On 2014-05-17 13:00, Valentin Hauner wrote:
I did not change the Makefile, so g++ is used for compiling (and not gcc). I've added
CXX_FLAGS = -lstdc++
but that doesn't help.
In addition to what Marcus already said, note that in many build systems adding a library to CXXFLAGS will not do what you want. CXXFLAGS is meant to contain parameters passed to the *compiler*, whereas LDFLAGS is GNU/Make's standard variable to contain *linker* flags.
Just nitpicking thouhg ;) Bjoern
l4-hackers@os.inf.tu-dresden.de