Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 960005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:06:47+00:00 2026-05-16T01:06:47+00:00

I have a problem with g++ building an application which links to a static

  • 0

I have a problem with g++ building an application which links to a static library, where the latter shall contain some global functions written in external asm-files, compiled with yasm. So in the library, I have

#ifdef __cplusplus
extern "C" {
#endif

extern void __attribute__((cdecl)) interp1( char *pSrc );
extern void __attribute__((cdecl)) interp2( char *pSrc );

#ifdef __cplusplus
}
#endif

which I reference elsewhere inside the library. Then, there is the implementation in an asm-file, like this:

section .data
; (some data)
section .text
; (some text)

global _interp1
_interp1:
    ; (code ...)
    ret

global _interp2
_interp2:
    ; (code ...)
    ret

Compiling and Linking work fine for the library, I do

yasm -f elf32 -O2 -o interp.o interp.asm

and then

ar -rc libInterp.a objs1.o [...] objsN.o interp.o 
ranlib libInterp.a

Now finally, to link the library to the main application, I do

g++ -O4 -ffast-math -DNDEBUG -fomit-frame-pointer -DARCH_X86 -fPIC -o ../bin/interp this.o that.o -lboost_thread -lpthread ./libInterp.a 

and I get the errors

undefined reference to `interp1'
undefined reference to `interp2'

What am I doing wrong here? any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:06:48+00:00Added an answer on May 16, 2026 at 1:06 am

    Depending on the target type, gcc will not prepend a leading underscore to external symbols. It appears that this is the case in your scenario.

    The simple fix is probably to remove the underscores from the names in your assembly file.

    A couple alternatives you might consder might be to use something like one of the following macros for your symbols in the assembly file:

    • from http://svn.xiph.org/trunk/oggdsf/src/lib/codecs/webm/libvpx/src/vpx_ports/x86_abi_support.asm

      ; sym()
      ; Return the proper symbol name for the target ABI.
      ;
      ; Certain ABIs, notably MS COFF and Darwin MACH-O, require that symbols
      ; with C linkage be prefixed with an underscore.
      ;
      %ifidn   __OUTPUT_FORMAT__,elf32
      %define sym(x) x
      %elifidn __OUTPUT_FORMAT__,elf64
      %define sym(x) x
      %elifidn __OUTPUT_FORMAT__,x64
      %define sym(x) x
      %else
      %define sym(x) _ %+ x
      %endif
      
    • from http://www.dcs.warwick.ac.uk/~peter/otherstuff.html

      %macro public_c_symbol 1
      GLOBAL %1,_%1
      %1:
      _%1:
      %endmacro
      
      public_c_symbol my_external_proc:
          ; ...
          RET
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.