You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I'm trying to compile a simple test program that uses two different copies of jemalloc in the same program statically. I think it's working, but I have a few compile warnings that I would like to resolve if possible (or at least confirm they are a non-issue).
My setup is the following. I have two copies of the jemalloc source, one in a subdirectory called jemalloc and the other in a subdirectory called jemalloc-other. The former I configure and compile as normal (i.e. no special options other than --enable-stats. The second I configure using:
I then compile the above using gcc -o main -I./jemalloc/include main.c ./jemalloc/lib/libjemalloc.a ./jemalloc-other/lib/libjemallocother.a -lpthread -ldl
This gives the following compiler warnings:
main.c: In function ‘main’:
main.c:19:27: warning: implicit declaration of function ‘othermalloc’ [-Wimplicit-function-declaration]
19 | void* p2 = (void*)othermalloc(512);
| ^~~~~~~~~~~~~~~
main.c:19:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
19 | void* p2 = (void*)othermalloc(512);
| ^
main.c:21:9: warning: implicit declaration of function ‘othermallctl’ [-Wimplicit-function-declaration]
21 | othermallctl("thread.allocated", &cnt, &cnt_sz, NULL, 0);
However, when I run the program it seems to work OK (i.e. the symbols are resolved and the allocations seem to come from different allocator instances):
I'm a little confused as to how to get rid of the above warnings. I tried including different header files from jemalloc-other/include (e.g. jemalloc-other/include/jemallocother.h), but it didn't seem to make a difference. Am I missing something?
The text was updated successfully, but these errors were encountered:
I have some experience loading two different versions of jemalloc, but our usage was a bit different
We were loading them as shared libraries instead of static linking
We were using two different versions of jemalloc instead of two builds of the same version (each built with a different with-jemalloc-prefix)
We never tried using them both in the same .c/.cpp file.
That said, I can share what worked for us.
In out experience, the jemalloc.h header file was not renamed with the various namespacing configurations, so we had to include both jemalloc.h files. It looks like you're passing -I./jemalloc/include on the compiler command line. I'd imagine you need to also pass -I./jemalloc-other/include to make the headers from the other install visible.
The problem with that is that now if you just #include "jemalloc/jemalloc.h", the name is ambiguous, so the compiler will just include the first one it finds. To get around that, we put a symlink in the different jemalloc directories, so that we could do things like
We added the include_public directories and the symlinks, the rest is just the normal jemalloc repo.
Then we pass -I./jemallocA/include_public and -I./jemallocB/include_public to the compiler, and in the code we can include both header files as "jemallocA/jemalloc.h" and "jemallocB/jemalloc.h".
Hi,
I'm trying to compile a simple test program that uses two different copies of jemalloc in the same program statically. I think it's working, but I have a few compile warnings that I would like to resolve if possible (or at least confirm they are a non-issue).
My setup is the following. I have two copies of the jemalloc source, one in a subdirectory called
jemalloc
and the other in a subdirectory calledjemalloc-other
. The former I configure and compile as normal (i.e. no special options other than--enable-stats
. The second I configure using:./configure --enable-stats --with-jemalloc-prefix=other --with-private-namespace=other_ --with-install-suffix=other
I have the following test program (
main.c
):I then compile the above using
gcc -o main -I./jemalloc/include main.c ./jemalloc/lib/libjemalloc.a ./jemalloc-other/lib/libjemallocother.a -lpthread -ldl
This gives the following compiler warnings:
However, when I run the program it seems to work OK (i.e. the symbols are resolved and the allocations seem to come from different allocator instances):
I'm a little confused as to how to get rid of the above warnings. I tried including different header files from
jemalloc-other/include
(e.g.jemalloc-other/include/jemallocother.h
), but it didn't seem to make a difference. Am I missing something?The text was updated successfully, but these errors were encountered: