1

I am trying to compile and run the following simple code in MAC OS X 10.9 with CLANG++:

#include "ACE_wrappers/ace/MEM_Stream.h"
#include <iostream>

int main()
{
        std::cout << "Hello World" << std::endl;
        ACE_MEM_Stream m(3);
        m.close_reader();
        return 0;
}

But I get the following error:

QAs-MacBook:aceTestLinking Moamen$ clang++ myTest.cpp 
Undefined symbols for architecture x86_64:
  "ace_os_main_i(int, char**)", referenced from:
       _main in moamen-511a28.o
  "ACE_SOCK::ACE_SOCK()", referenced from:
       ACE_MEM_IO::ACE_MEM_IO() in moamen-511a28.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The compile line:

clang++ myTest.cpp

The CLANG Compiler version I am using:

QAs-MacBook:aceTestLinking Moamen$ clang++ --version
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

Notice - I have also tried to compile with "-std=c++11", "-stdlib=libstdc++", as in the following topic: C++ linking error after upgrading to Mac OS X 10.9 / Xcode 5.0.1 but did not solve the issue.

Thanks,

Moamen

Community
  • 1
  • 1
MK3
  • 56
  • 8
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Anton Savin Nov 18 '14 at 09:35
  • Apparently you aren't linking with ACE library. – Anton Savin Nov 18 '14 at 09:37
  • Notice same code worked before in older OS X (10.8 and below), but after CLANG compiler update, it's not working (before I used g++, not clang++). – MK3 Nov 18 '14 at 09:40
  • I have tried to run **clang++ myTest.cpp -I ACE_wrappers/lib** still getting the same error – MK3 Nov 18 '14 at 09:45
  • `-l` and `-L` are different compiler options, I believe you have to specify them both with correct values. – Anton Savin Nov 18 '14 at 09:49
  • You have to link the ACE library with -lACE, else it will not work. See how we compile and link one of the ACE unit tests – Johnny Willemsen Nov 19 '14 at 07:12
  • Thanks for the replies, after some investigation on Linux Ubuntu, I succeeded to compile the code with the following command **g++ -o m.out myTest.cpp ACE_wrappers/lib/libACE.a -I ACE_wrappers/ -lpthread -ldl**. Seems some default libs were missing! – MK3 Nov 19 '14 at 07:59
  • For MAC OS X - it was my mistake, I needed to include correctly some libs / header files, i.e. **clang++ myTest.cpp ACE_wrappers/lib/libACE.a -I ACE_wrappers/**. – MK3 Nov 19 '14 at 08:16

1 Answers1

0

Thanks for the replies, after some investigation on Linux Ubuntu, I succeeded to compile the code with the following command g++ -o m.out myTest.cpp ACE_wrappers/lib/libACE.a -I ACE_wrappers/ -lpthread -ldl. Seems some default libs were missing!

Johnny Willemsen
  • 2,942
  • 1
  • 14
  • 16