0

Building C++ app using xerces, here is where it worked, on the build part

g++ -I/usr/local/include/xercesc -O0 -g3 -Wall -c -fmessage-length=0 -v -MMD -MP -MF"mypoject/xercesserver.d" -MT"myproject/xercesserver.o" -o "myproject/xercesserver.o" "../myproject/xercesserver.c"
...etc,etc, blah, blah, blah

Here is where it failed, linking

gcc -L/usr/local/lib -lxerces-c -o "myprojectapp" ./myproject/textfileread.o ./myproject/xercesserver.o
Undefined symbols for architecture x86_64:
  "vtable for __cxxabiv1::__class_type_info", referenced from:
  typeinfo for xercesc_3_2::XMLDeleter in xercesserver.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"operator delete(void*)", referenced from:
  xercesc_3_2::XMLDeleter::~XMLDeleter() in xercesserver.o
"___cxa_begin_catch", referenced from:
  _main in xercesserver.o
"___cxa_end_catch", referenced from:
  _main in xercesserver.o
"___gxx_personality_v0", referenced from:
  xercesc_3_2::XMLDeleter::~XMLDeleter() in xercesserver.o
  _main in xercesserver.o
  Dwarf Exception Unwind Info (__eh_frame) in xercesserver.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Mac 10.13.1 High Sierra, Xerces 3.2, Eclipse Oxygen 3.a, CDT 9.4.3, gcc g++ both

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.2.0
InstalledDir: /Library/Developer/CommandLineTools/usr/bin 

A symbolic link, g++ -> gcc , but binaries differ in /usr/bin though same size.

chars
  • 343
  • 3
  • 10

1 Answers1

0

Problem originated by creating C++ Project, C Managed Build, instead of a C++ Project, C++ Managed Build, which then necessitated the corrective given below. I had begun working on a C code project and later realized I needed the xerces code, which of course is C++. Otherwise you would just need to add the library as in the following image.

Add xerces-c and /usr/local/lib

Note that the actual file's name is libxerces-c.a in the directory /usr/local/lib but Eclipse wants you to just give the root name, meaning xerces-c.

Now for the error caused by creating a C Managed build, a good clue was found here: How can I fix g++ Undefined symbols for architecture x86_64 error?

Problem finding this was partly that Eclipse is using g++ for the compiling but then gcc by default for the linking. So the problem is really how to fix gcc, not g++, and then the solution is actually to switch to g++. Also xerces FAQs brings up similar issues with different solutions. Attached pix shows the place to fix in Eclipse. enter image description here

chars
  • 343
  • 3
  • 10
  • I might add that the xerces issues mentioned are about linking, not Eclipse, and have different solutions because the root causes are not the same. – chars Jan 20 '22 at 06:18
  • Another nuance or stupid mistake one could make is to make a file using C++ xerces code or lib, but naming it with a .c extension. In that case even the C++ Managed Build will use gcc instead g++ and the code will display errors and the build will fail. – chars Jan 21 '22 at 05:29