Hello,
When I try to build the app below in Genode, the following linking error happens:
main.o: In function `main':
.../main.cc:6: undefined reference to `malloc(unsigned int)'
.../main.cc:8: undefined reference to `free(void*)'
What am I missing here? Thanks!
Amadeo
::::::::::::::
main.cc
::::::::::::::
#include <stdlib.h>
#define N 10
int main(void) {
int *v = (int *) malloc(N*sizeof(int));
for (int i=0; i<N; i++) v[i] = i;
free(v);
}
::::::::::::::
target.mk
::::::::::::::
TARGET = foo
SRC_CC = main.cc
LIBS = cxx env mini_c
Hello Amadeo,
if you really want to use stdlib's malloc and free, you'll have to link against our 'libc'. The 'mini_c' library you've choosen doesn't provide malloc/free. It's just a small dummy library for the png-library in our demo-repository, that provides a few string-handling functions.
If you only need malloc/free without additional libc functionality, there is a simple implementation in our C++ support-library in:
base/src/base/cxx/malloc_free.cc
which uses the heap-allocator from Genode's base environment. To not clash with the definition of e.g. the implementation in the 'libc' both symbols are hidden after linking the C++ support library, so you cannot use it directly, but it might help you as a starting point, if you don't want to link against whole 'libc'.
Regards Stefan
On 03/15/2011 08:53 PM, Amadeo Cuadrado wrote:
Hello,
When I try to build the app below in Genode, the following linking error happens:
main.o: In function `main':
…/main.cc:6: undefined reference to `malloc(unsigned int)'
…/main.cc:8: undefined reference to `free(void*)'
What am I missing here? Thanks!
Amadeo
::::::::::::::
main.cc
::::::::::::::
#include <stdlib.h>
#define N 10
int main(void) {
int *v = (int *) malloc(N*sizeof(int));
for (int i=0; i<N; i++) v[i] = i;
free(v);
}
::::::::::::::
target.mk
::::::::::::::
TARGET = foo
SRC_CC = main.cc
LIBS = cxx env mini_c
Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d
Genode-main mailing list Genode-main@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/genode-main
Thanks Stefan for your answer.
Would it be possible to statically link libc into my project?
Amadeo
-----Original Message----- From: Stefan Kalkowski [mailto:stefan.kalkowski@...1...] Sent: Tuesday, March 15, 2011 1:16 PM To: genode-main@lists.sourceforge.net Subject: Re: Use of malloc primitives in Genode
Hello Amadeo,
if you really want to use stdlib's malloc and free, you'll have to link against our 'libc'. The 'mini_c' library you've choosen doesn't provide malloc/free. It's just a small dummy library for the png-library in our demo-repository, that provides a few string-handling functions.
If you only need malloc/free without additional libc functionality, there is a simple implementation in our C++ support-library in:
base/src/base/cxx/malloc_free.cc
which uses the heap-allocator from Genode's base environment. To not clash with the definition of e.g. the implementation in the 'libc' both symbols are hidden after linking the C++ support library, so you cannot use it directly, but it might help you as a starting point, if you don't want to link against whole 'libc'.
Regards Stefan
On 03/15/2011 08:53 PM, Amadeo Cuadrado wrote:
Hello,
When I try to build the app below in Genode, the following linking error happens:
main.o: In function `main':
.../main.cc:6: undefined reference to `malloc(unsigned int)'
.../main.cc:8: undefined reference to `free(void*)'
What am I missing here? Thanks!
Amadeo
::::::::::::::
main.cc
::::::::::::::
#include <stdlib.h>
#define N 10
int main(void) {
int *v = (int *) malloc(N*sizeof(int));
for (int i=0; i<N; i++) v[i] = i;
free(v);
}
::::::::::::::
target.mk
::::::::::::::
TARGET = foo
SRC_CC = main.cc
LIBS = cxx env mini_c
Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d
Genode-main mailing list Genode-main@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/genode-main
Hi Amadeo,
When I try to build the app below in Genode, the following linking error happens:
…/main.cc:6: undefined reference to `malloc(unsigned int)' …/main.cc:8: undefined reference to `free(void*)'
What am I missing here? Thanks!
because you are using 'malloc' from within a C++ source file and the function in mini_c's 'stdlib.h' is not declared as 'extern "C"', the compiler generates a mangled C++ symbol. You can see this when looking at the object file for 'main.cc':
nm test/amadeo/main.o
U _Z4freePv U _Z6mallocj U __gxx_personality_v0 00000000 T main
Simple fix: Just put the the '#include <stdlib.h>' in an 'extern "C"' block:
extern "C" { #include <stdlib.h> }
In general, I would not recommend to use 'mini_c' because this library is just meant as a support library for our demo applications (it is actually part of the 'demo' repository). Hence, 'mini_c' is only tested for our particular demos.
I would try to avoid libc functionality altogether, e.g., by allocation memory via Genode's heap:
#include <base/env.h>
...
int *v = (int *)Genode::env()->heap()->alloc(N*sizeof(int));
Alternatively, if you really desire libc functionality, I'd recommend using our C runtime. For this, you will need to add 'libc' to your 'LIBS' declaration in our 'target.mk' file. Optionally, you may also want to add 'libc_log' if you like to use libc's fully-fledged 'printf' to operate with Genode's LOG service. Also make sure that you have listed the libc repository the 'REPOSITORIES' declaration in your '<build-dir>/etc/build.conf' file. When booting, do not forget to load 'ldso', 'libc.lib.so', and 'libc_log.lib.so' as boot modules.
Cheers Norman
*while looking at Norman's mail*: ok, thats my fault I missed the malloc/free implementation in 'mini_c', so it's just about C/C++ linkage differences.
On 03/15/2011 09:27 PM, Amadeo Cuadrado wrote:
Thanks Stefan for your answer.
Would it be possible to statically link libc into my project?
With respect to your question: of course, it's possible in general. I guess you like to use libc on top of Fiasco.OC, where ldso isn't enabled yet? Otherwise I would recommend you to use ldso instead.
Please try it, by uncommenting the following two lines in 'libc/lib/mk/libc.mk':
SHARED_LIB = yes LD_OPT += --version-script=$(REP_DIR)/src/lib/libc/Version.def
Regards Stefan
Amadeo
-----Original Message----- From: Stefan Kalkowski [mailto:stefan.kalkowski@...1...] Sent: Tuesday, March 15, 2011 1:16 PM To: genode-main@lists.sourceforge.net Subject: Re: Use of malloc primitives in Genode
Hello Amadeo,
if you really want to use stdlib's malloc and free, you'll have to link against our 'libc'. The 'mini_c' library you've choosen doesn't provide malloc/free. It's just a small dummy library for the png-library in our demo-repository, that provides a few string-handling functions.
If you only need malloc/free without additional libc functionality, there is a simple implementation in our C++ support-library in:
base/src/base/cxx/malloc_free.cc
which uses the heap-allocator from Genode's base environment. To not clash with the definition of e.g. the implementation in the 'libc' both symbols are hidden after linking the C++ support library, so you cannot use it directly, but it might help you as a starting point, if you don't want to link against whole 'libc'.
Regards Stefan
On 03/15/2011 08:53 PM, Amadeo Cuadrado wrote:
Hello,
When I try to build the app below in Genode, the following linking error happens:
main.o: In function `main':
.../main.cc:6: undefined reference to `malloc(unsigned int)'
.../main.cc:8: undefined reference to `free(void*)'
What am I missing here? Thanks!
Amadeo
::::::::::::::
main.cc
::::::::::::::
#include <stdlib.h>
#define N 10
int main(void) {
int *v = (int *) malloc(N*sizeof(int));
for (int i=0; i<N; i++) v[i] = i;
free(v);
}
::::::::::::::
target.mk
::::::::::::::
TARGET = foo
SRC_CC = main.cc
LIBS = cxx env mini_c
Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d
Genode-main mailing list Genode-main@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/genode-main
On 03/15/2011 09:45 PM, Stefan Kalkowski wrote:
*while looking at Norman's mail*: ok, thats my fault I missed the malloc/free implementation in 'mini_c', so it's just about C/C++ linkage differences.
On 03/15/2011 09:27 PM, Amadeo Cuadrado wrote:
Thanks Stefan for your answer.
Would it be possible to statically link libc into my project?
With respect to your question: of course, it's possible in general. I guess you like to use libc on top of Fiasco.OC, where ldso isn't enabled yet? Otherwise I would recommend you to use ldso instead.
Please try it, by uncommenting the following two lines in 'libc/lib/mk/libc.mk':
SHARED_LIB = yes LD_OPT += --version-script=$(REP_DIR)/src/lib/libc/Version.def
oh sorry again, I meant commenting these lines out - of course! I think I was a little bit tired yesterday evening :-)
Regards Stefan
Regards Stefan
Amadeo
-----Original Message----- From: Stefan Kalkowski [mailto:stefan.kalkowski@...1...] Sent: Tuesday, March 15, 2011 1:16 PM To: genode-main@lists.sourceforge.net Subject: Re: Use of malloc primitives in Genode
Hello Amadeo,
if you really want to use stdlib's malloc and free, you'll have to link against our 'libc'. The 'mini_c' library you've choosen doesn't provide malloc/free. It's just a small dummy library for the png-library in our demo-repository, that provides a few string-handling functions.
If you only need malloc/free without additional libc functionality, there is a simple implementation in our C++ support-library in:
base/src/base/cxx/malloc_free.cc
which uses the heap-allocator from Genode's base environment. To not clash with the definition of e.g. the implementation in the 'libc' both symbols are hidden after linking the C++ support library, so you cannot use it directly, but it might help you as a starting point, if you don't want to link against whole 'libc'.
Regards Stefan
On 03/15/2011 08:53 PM, Amadeo Cuadrado wrote:
Hello,
When I try to build the app below in Genode, the following linking error happens:
main.o: In function `main':
.../main.cc:6: undefined reference to `malloc(unsigned int)'
.../main.cc:8: undefined reference to `free(void*)'
What am I missing here? Thanks!
Amadeo
::::::::::::::
main.cc
::::::::::::::
#include <stdlib.h>
#define N 10
int main(void) {
int *v = (int *) malloc(N*sizeof(int));
for (int i=0; i<N; i++) v[i] = i;
free(v);
}
::::::::::::::
target.mk
::::::::::::::
TARGET = foo
SRC_CC = main.cc
LIBS = cxx env mini_c
Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d
Genode-main mailing list Genode-main@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/genode-main