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

  • SEARCH
  • Home
  • 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 8850681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:57:30+00:00 2026-06-14T12:57:30+00:00

I am trying to compile some simple code using the libav libraries. // Some

  • 0

I am trying to compile some simple code using the libav libraries.

// Some simple code to demonstrate
#include <libavformat/avformat.h>

int main(int argc, char *argv[]) {
    av_register_all();
    return 0;
}

I’m on a Mac, with gcc version 4.2.1.

When I try to compile the code as C using

gcc -o main main.c -lavformat

then the code compiles and links fine. However, when I try to compile it as C++ using

g++ -o main main.cpp -lavformat

it gives me undefined symbols errors:

Undefined symbols for architecture x86_64:
  "av_register_all()", referenced from:
      _main in ccQ23HMe.o

When I run with the -v option, the linking steps run are:

// gcc
"/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.8.0 -o c
 /var/folders/r0/n22t1hyn7ts92jxgd9_pn8yw0000gn/T/main-uUfZkM.o -lavformat
-lSystem /usr/bin/../lib/clang/4.1/lib/darwin/libclang_rt.osx.a

// g++
"/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.8.0 -o c
 /var/folders/r0/n22t1hyn7ts92jxgd9_pn8yw0000gn/T/main-5QU6fj.o -lavformat
 -lstdc++ -lSystem /usr/bin/../lib/clang/4.1/lib/darwin/libclang_rt.osx.a

Here, the only difference is the addition of -lstdc++ to the linking.

Why are these undefined symbol errors appearing? Is there some reason that simply adding a library to the linking would cause these undefined symbols? Or is there something else that is causing this problem, perhaps specifically related to libavformat?

  • 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-06-14T12:57:32+00:00Added an answer on June 14, 2026 at 12:57 pm

    The libav “Frequently Asked Questions” list covers this exact scenario!

    Here, the only difference is the addition of -lstdc++ to the linking.

    Nope — that, and you’re using a different language with different default calling conventions.

    av_register_all as declared in the header is not marked extern "C", whereas the definition in the actual compiled library requires good old-fashioned C calling convention.

    Surround your libav includes with extern "C".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just trying to compile some simple example code I typed in from
I am trying to use some sample code and my compiler won't compile this
I'm trying to compile some code which contains the following declaration, because I would
I'm trying to compile some fortran files in Xcode, using a makefile made by
I'm currently trying to compile some code examples from http://developer.gnome.org/gtkmm-tutorial/unstable/sec-treeview-examples.html.en but from what I
I am using VC2010, trying to compile some library written in C99 for Linux.
I'm trying to compile with g++ some code previously developed under Visual C++ 2008
I'm trying to follow the steps to compile some C code to import into
I have some simple test code which I am trying to generate AVX optimized
I am trying to write some simple Rcpp code examples. This is remarkably easy

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.