Hello lzSun,
On Mon, Sep 17, 2018 at 05:30:17PM +0800, lzSun wrote:
I want to build a component which needs both C++ and C files, however, I encountered some problem when I compiling them together. Here's the error: libc.lib.so: undefined reference to `Libc::Component::construct(Libc::Env&)' collect2: error: ld returned 1 exit status
This error is not related to your mix of C and C++ sources in one program. The cause is that you missed to implement the mentioned function Libc::Component::construct(), which is the entrypoint for libc-based components in Genode. The equivalent is the main() function in the C standard and you may restore this behavior in Genode by adding
LIBS += posix
to your library dependencies in target.mk for your program.
As a background, we deprecated the use of the original main() function for Genode components some years ago because it depends on global resources, which are accessible to all software modules for the whole runtime of the component. In contrast, Genode components come alive in the Genode::construct() function, which is passed a reference to the Genode::Env for dedicated access to program resources. If further moduels need access to resources references must be passed explcitly, which prevents unintended side effects. Later we adapted this pattern for libc-based components too and the _posix_ library is there just for backwards compatibility of ported traditional applications.
Greets