build error -- can not find operator new

This is a discussion on build error -- can not find operator new within the C Programming forums, part of the General Programming Boards category; Hello everyone, I am using Red Hat Enterprise Linux 4 with gcc version 3.4.5. Here is my issue, 1. I ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    build error -- can not find operator new

    Hello everyone,


    I am using Red Hat Enterprise Linux 4 with gcc version 3.4.5. Here is my issue,

    1. I have a shared library called libA.so wirtten in C++ and has C interface (extern C wrapper);
    2. I have another shared called libB.so, which is written in C and is dependent on libA.so, and I am using -lA to build shared library libB.so and it is successful;
    3. I have an application called C, which is written in C and is dependent on shared library libB.so, and when using -lB -lA to build the application C, here are the link error messages,

    .//libA.so: undefined reference to `operator new[](unsigned int)
    .//libA.so: undefined reference to `operator delete(void*)
    .//libA.so: undefined reference to `__gxx_personality_v0

    For the whole process, I am using gcc other than g++. And I am wondering how to solve this issue in step 3?

    I think we are able to build C application with dependent C++ shared library, right?


    thanks in advance,
    George

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Add -lg++ I think.

    Or use "g++" to link your application, and it should add it by default - there is no reason you can't compile and link with g++ even for plain C.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,851
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    2,053
    Quote Originally Posted by Salem View Post
    If the library is built with a C wrapper, then presumably it is intended to be callable from a C program.

    I would look at the library vender's site. There is no standard way to link C++ source code into a C program. C does not have any portable functionality to link code written in any language accept assembly. If somebody wrote a library in C++ that an be called from C, it would be up to them to explain how to link the code.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  5. #5
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    You need to link with -lstdc++.

    But really, you should be using g++ to link, not gcc. It doesn't matter if the code is C or C++, g++ can link it either way.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ld.exe: cannot find -l-lstdc++
    By Tonto in forum Tech Board
    Replies: 3
    Last Post: 04-11-2007, 12:20 AM
  2. any SDK for build binaries on ARM5 platform?
    By George2 in forum Tech Board
    Replies: 0
    Last Post: 12-14-2006, 11:23 PM
  3. Won't Return pointer, i can't find why...
    By ss3x in forum C++ Programming
    Replies: 2
    Last Post: 02-28-2002, 08:50 PM
  4. Variable question I can't find answer to
    By joelmon in forum C++ Programming
    Replies: 3
    Last Post: 02-12-2002, 04:11 AM
  5. RE: Find out running processes from command prompt
    By sampatel in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-18-2001, 08:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21