Gcc Error Aliased To Undefined Symbol
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Aliasing a function on a C interface within a C++ application on Linux up vote 1 down vote favorite I am compiling a c interface on my library (GCC 4.4.4-14 ubuntu 5.1), which essentially looks like this header extern "C" { int foo() } implementation int foo() {} int bar() __attribute__((alias ("foo"))); This compiles fine, but when I link the shared object to a test application, and try and call bar(), the function is not recognised. I tried moving the alias line from implementation to header, and then i get a compiler error: bar() aliased to undefined symbol foo Why does moving the alias to the header, result in this error? and how do i get it all working please? c++ c linux interface alias share|improve this question asked May 29 '12 at 15:38 user1424106 183 Does shared library have symbol bar somewhere? –maverik May 29 '12 at 15:44 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote extern "C" needs for implementation. extern "C" { int foo(); } extern "C" // <<< extern "C" also!!! { int foo() {} } int bar() __attribute__((alias ("foo"))); share|improve this answer answered May 29 '12 at 15:43 booiljoung 33528 Thanks for the reply @booiljoung, with your suggested changes my test application has a compile error with: error: 'bar' was not declared in this scope. –user1424106 May 29 '12 at 16:21 int bar() is not in a header file, i was not aware that was how the alias worked. –user1424106 May 29 '12 at 16:36 Jay mean some proccessor not support attribute. right? Jay? –booiljoung May 29 '12 at 16:57 Yes. As I understand it, yes. –Jay May 30 '12 at 5:43 add a comment| up vote 0 down vote Apart from booiljoung's answer above, you might also find the below information from gcc site useful: alias ("target") The alias attribute causes the declaration to be emitted as an alias
User account creation filtered due to spam. Bug20652 - rejects code with an error: aliased to undefined symbol Summary: rejects code with an error: aliased to undefined symbol Status: RESOLVED INVALID Alias: None Product: gcc Classification: Unclassified Component: c (show other bugs) Version: 4.0.0 Importance: P2 normal Target Milestone: --- Assignee: Not yet assigned to http://stackoverflow.com/questions/10802324/aliasing-a-function-on-a-c-interface-within-a-c-application-on-linux anyone URL: Keywords: rejects-valid Duplicates (1): 23245 (view as bug list) Depends on: Blocks: Reported: 2005-03-26 23:58 UTC by Serge Belyshev Modified: 2005-08-05 15:27 UTC (History) CC List: 3 users (show) gcc-bugs rth whatdoineed2do See Also: Host: Target: Build: Known to work: Known to fail: Last reconfirmed: Attachments https://gcc.gnu.org/bugzilla/show_bug.cgi?id=20652 Add an attachment (proposed patch, testcase, etc.) Note You need to log in before you can comment on or make changes to this bug. Description Serge Belyshev 2005-03-26 23:58:09 UTC ------------------------------------------------------------------------------ extern int foo; extern int bar __attribute__ ((alias ("foo"))); ------------------------------------------------------------------------------ $ gcc foo.i foo.i:2: error: ‘bar’ aliased to undefined symbol ‘foo’ $ this code is taken from glibc/sysdeps/wordsize-64/wcstol_l.c and it was accepted by gcc 3.4 and earlier. Comment 1 Andreas Jaeger 2005-03-27 08:16:25 UTC glibc needs to be changed for this, for details chech the thread starting at: http://sourceware.org/ml/libc-hacker/2005-03/msg00061.html Comment 2 Andrew Pinski 2005-08-05 15:27:14 UTC *** Bug 23245 has been marked as a duplicate of this bug. *** Format For Printing -XML -Clone This Bug -Top of page Home | New | Browse | Search | [?] | Reports | Help | NewAccount | Log In Remember [x] | Forgot Password Login: [x]
message: [mpich-devel] Weak symbols, clang, and users compiling with -fvisibility=hidden Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] MPICH's test for weak symbols http://lists.mpich.org/pipermail/devel/2014-January/000299.html is: int foo(int) __attribute__((weak,alias("__foo"))); where __foo is not defined in the same compilation unit. This fails with gcc (tested with 4.8 and 4.4): conftest.c:37:5: error: 'foo' aliased to undefined symbol '__foo' https://forums.wxwidgets.org/viewtopic.php?t=6849 int foo(int) __attribute__((weak,alias("__foo"))); ^ This is (evidently) a change from gcc-3.x, but is intentional because knowledge of the weak alias is not desirable/meaningful in other compilation units. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20652 My understanding of gcc error gcc's intent is that the attribute only be stated in the implementation. The caller can't do anything with the information that foo is a weak alias; it still needs to generate a PLT entry and the loader will need to perform a relocation. Now my problem is that clang accepts the test code above (i.e., it does not insist that __foo gcc error aliased be defined in the same compilation unit) which causes #define MPICH_ATTR_WEAK_ALIAS(fname) __attribute__((weak,alias(fname))) but this breaks PMPI and when -fvisibility=hidden is used to compile user code, it generates (objdump -r) RELOCATION RECORDS FOR [.text]: OFFSET TYPE VALUE 0000000000000005 R_X86_64_PC32 __foo-0x0000000000000004 instead of the linkable (but not desired because it prevents interposing "foo") RELOCATION RECORDS FOR [.text]: OFFSET TYPE VALUE 0000000000000005 R_X86_64_PLT32 __foo-0x0000000000000004 What we actually want is an honest relocation for "foo": RELOCATION RECORDS FOR [.text]: OFFSET TYPE VALUE 0000000000000005 R_X86_64_PLT32 foo-0x0000000000000004 When you try to link the first version later, you get /usr/bin/ld.gold: error: bar.o: requires dynamic R_X86_64_PC32 reloc against '__foo' which may overflow at runtime; recompile with -fPIC which is not actually an -fPIC error, but rather a result of clang using R_X86_64_PC32 for a symbol that we really want to be R_X86_64_PLT32. I think this should probably be reported to Clang/LLVM (because it delays a confusing error condition), but I also think that MPICH should fix its usage. So in summary, we can't have __attribute__((weak,alias("PMPI_..."))) in the header because: 1. it does not compile with gcc 2. it breaks PMPI interp
Compiler / Linking / IDE Related Search Compiling wxWidgets 2.6.3-RC1 with GCC 4.1 (MinGW) Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here. Post Reply Print view Search Advanced search 15 posts • Page 1 of 1 MichaelZ In need of some credit Posts: 6 Joined: Thu Mar 02, 2006 1:16 pm Contact: Contact MichaelZ ICQ Website WLM Compiling wxWidgets 2.6.3-RC1 with GCC 4.1 (MinGW) Quote Postby MichaelZ » Thu Mar 02, 2006 1:23 pm Hello, I am trying to compile wxWidgets 2.6.3-RC1 with GCC 4.1 (MinGW), but I get an error: ../../src/msw/ole/activex.cpp: At global scope:../../src/msw/ole/activex.cpp:854: error: 'ULONG *LTHUNK0()' aliased to undefined symbol '_ZN9FrameSite7ReleaseEv'../../src/msw/ole/activex.cpp:854: error: 'ULONG *LTHUNK1()' aliased to undefined symbol '_ZN9FrameSite7ReleaseEv'../../src/msw/ole/activex.cpp:854: error: 'ULONG *LTHUNK2()' aliased to undefined symbol '_ZN9FrameSite7ReleaseEv'../../src/msw/ole/activex.cpp:854: error: 'ULONG *LTHUNK3()' aliased to undefined symbol '_ZN9FrameSite7ReleaseEv'../../src/msw/ole/activex.cpp:854: error: 'ULONG *LTHUNK4()' aliased to undefined symbol '_ZN9FrameSite7ReleaseEv'../../src/msw/ole/activex.cpp:854: error: 'ULONG *LTHUNK5()' aliased to undefined symbol '_ZN9FrameSite7ReleaseEv'../../src/msw/ole/activex.cpp:854: error: 'ULONG *LTHUNK6()' aliased to undefined symbol '_ZN9FrameSite7ReleaseEv'../../src/msw/ole/activex.cpp:854: error: 'ULONG *LTHUNK7()' aliased to undefined symbol '_ZN9FrameSite7ReleaseEv'../../src/msw/ole/activex.cpp:854: error: 'ULONG *LTHUNK8()' aliased to undefined symbol '_ZN9FrameSite6AddRefEv'../../src/msw/ole/activex.cpp:854: error: 'ULONG *LTHUNK9()' aliased to undefined symbol '_ZN9FrameSite6AddRefEv'../../src/msw/ole/activex.cpp:854: error: 'ULONG *LTHUNK10()' aliased to undefined symbol '_ZN9FrameSite6AddRefEv'../../src/msw/ole/activex.cpp:854: error: 'ULONG *LTHUNK11()' aliased to undefined symbol '_ZN9FrameSite6AddRefEv'../../src/msw/ole/activex.cpp:854: error: 'ULONG *LTHUNK12()' aliased to undefined symbol '_ZN9FrameSite6AddRefEv'../../src/msw/ole/activex.cpp:854: error: 'ULONG *LTHUNK13()' alia