{"action":"created","issue":{"url":"https://api.github.com/repos/jemalloc/jemalloc/issues/442","repository_url":"https://api.github.com/repos/jemalloc/jemalloc","labels_url":"https://api.github.com/repos/jemalloc/jemalloc/issues/442/labels{/name}","comments_url":"https://api.github.com/repos/jemalloc/jemalloc/issues/442/comments","events_url":"https://api.github.com/repos/jemalloc/jemalloc/issues/442/events","html_url":"https://github.com/jemalloc/jemalloc/issues/442","id":169213532,"number":442,"title":"Unable to compile with -static ","user":{"login":"bassamtabbara","id":1463491,"avatar_url":"https://avatars.githubusercontent.com/u/1463491?v=3","gravatar_id":"","url":"https://api.github.com/users/bassamtabbara","html_url":"https://github.com/bassamtabbara","followers_url":"https://api.github.com/users/bassamtabbara/followers","following_url":"https://api.github.com/users/bassamtabbara/following{/other_user}","gists_url":"https://api.github.com/users/bassamtabbara/gists{/gist_id}","starred_url":"https://api.github.com/users/bassamtabbara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bassamtabbara/subscriptions","organizations_url":"https://api.github.com/users/bassamtabbara/orgs","repos_url":"https://api.github.com/users/bassamtabbara/repos","events_url":"https://api.github.com/users/bassamtabbara/events{/privacy}","received_events_url":"https://api.github.com/users/bassamtabbara/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-08-03T19:31:06Z","updated_at":"2016-08-13T06:08:17Z","closed_at":null,"body":"I'm unable to compile a simple static program with jemalloc. I'm using the jemalloc-dev package on Ubuntu and I've not compiled it from source. Here's a very simple repro:\r\n\r\n```\r\n#include <stdlib.h>\r\n\r\nint main() {\r\n  void *i = malloc(0);\r\n  return 0;\r\n}\r\n```\r\n\r\nWhen I compile this I get the following:\r\n\r\n```\r\n> g++ test.c -o test -static -ljemalloc -lpthread\r\n/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libc.a(malloc.o): In function `__libc_malloc':\r\n(.text+0x6120): multiple definition of `malloc'\r\n/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libjemalloc.a(jemalloc.o):(.text+0x27d0): first defined here\r\n/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libc.a(malloc.o): In function `__libc_free':\r\n(.text+0x6620): multiple definition of `free'\r\n/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libjemalloc.a(jemalloc.o):(.text+0xc80): first defined here\r\n/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libc.a(malloc.o): In function `__libc_realloc':\r\n(.text+0x67e0): multiple definition of `realloc'\r\n/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libjemalloc.a(jemalloc.o):(.text+0x1510): first defined here\r\ncollect2: error: ld returned 1 exit status\r\n```\r\n\r\nFWIW, when using tcmalloc it compiles fine:\r\n\r\n```\r\n> g++ test.c -o test -static -ltcmalloc_minimal -lpthread\r\n> ./test\r\n```\r\n\r\nDo I need to build jemalloc with different options to enable this?\r\n"},"comment":{"url":"https://api.github.com/repos/jemalloc/jemalloc/issues/comments/239604767","html_url":"https://github.com/jemalloc/jemalloc/issues/442#issuecomment-239604767","issue_url":"https://api.github.com/repos/jemalloc/jemalloc/issues/442","id":239604767,"user":{"login":"kspinka","id":1490618,"avatar_url":"https://avatars.githubusercontent.com/u/1490618?v=3","gravatar_id":"","url":"https://api.github.com/users/kspinka","html_url":"https://github.com/kspinka","followers_url":"https://api.github.com/users/kspinka/followers","following_url":"https://api.github.com/users/kspinka/following{/other_user}","gists_url":"https://api.github.com/users/kspinka/gists{/gist_id}","starred_url":"https://api.github.com/users/kspinka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kspinka/subscriptions","organizations_url":"https://api.github.com/users/kspinka/orgs","repos_url":"https://api.github.com/users/kspinka/repos","events_url":"https://api.github.com/users/kspinka/events{/privacy}","received_events_url":"https://api.github.com/users/kspinka/received_events","type":"User","site_admin":false},"created_at":"2016-08-13T06:08:17Z","updated_at":"2016-08-13T06:08:17Z","body":"Yeah, sorry, I didn't read carefully, you have two choices:\r\n\r\n1. Drop the -static (don't worry, this is still including static versions of your libs, just not the system libs.  This is my preferred approach.\r\n```\r\ng++ -o test test.c jemalloc/lib/libjemalloc.a -lpthread\r\n```\r\n\r\n2. gcc's optimizer should allow this if you insist on statically linking libc.  I don't recommend this at all.\r\n```\r\ng++ -Ofast -o test test.c jemalloc/lib/libjemalloc.a -lpthread -static\r\n```"}}
{"actor":{"display_login":"kspinka"}}