What is the difference between clang and clang ++ when building a library?

I compiled a c library (for use by a C ++ project) with clang. When I tried to link this library, I got linker errors (in particular, the undefined character relative to the hqxInit function). When I switch to clang ++, it works. Checking with nm, clang ++ calls the names again. What happens, and is there a better way to tell the linker that the library is running for-c versus munged-for-C ++? It seems silly to create a c library with C ++ ....

// built with clang

$ nm libhqx.a libhqx.bak(init.co) 04000000 C _RGBtoYUV 00000004 C _YUV1 00000004 C _YUV2 00000000 T _hqxInit 

// built using clang ++

 $ nm libhqx.a libhqx.a(init.o): 00000100 S _RGBtoYUV 04000100 S _YUV1 04000104 S _YUV2 00000000 T __Z7hqxInitv 
+4
source share
1 answer

clang and clang++ are the same executable for most systems. One is just a symbolic link to another.

The program checks for what name it is called, and:

  • for clang , compiles code like C
  • for clang++ , compiles code as C ++

In C ++, the compiler generates names for functions in different ways than C - this is because you can have several functions with the same (but different) parameters. This is called the "name" - and this is what you see.

You can use a tool called c++filt to "untie" names.

Example:

 $ c++filt __Z7hqxInitv hqxInit() 

More info here: why does clang ++ behave differently than clang since the former is a symbolic link of the latter?

+8
source

All Articles