Visar inlägg med etikett gcc. Visa alla inlägg
Visar inlägg med etikett gcc. Visa alla inlägg

söndag 2 december 2018

Get the default include paths from Clang


When porting our code to build for Win32 with Clang, on macOS, I got a bunch of intrinsics errors:


/usr/local/opt/llvm/bin/lld-link: error: dlib.lib(image_2.o): undefined symbol: __cpuid
/usr/local/opt/llvm/bin/lld-link: error: dlib.lib(image_2.o): undefined symbol: _mm_setr_epi16
/usr/local/opt/llvm/bin/lld-link: error: dlib.lib(image_2.o): undefined symbol: _mm_set1_epi32
/usr/local/opt/llvm/bin/lld-link: error: dlib.lib(image_2.o): undefined symbol: _mm_load_si128


This error is a bit unusual (for me at least) so it threw me off, since I had obviously linked against the dlib.lib before, only difference, it was using CL.exe at that time.

This isn't due to a missing library, but in fact a missing include.
And as it turns out, the order of includes.

The compiler checks the include file(s) to see what symbols to put in there, and if it recognises it, it outputs the correct intrinsic function in the code. Otherwise, it's unresolved, and will later become undefined.

And, in order to make the code a bit more resilient towards compiler version updates, I wanted to grep the include paths in a simple fashion on both OSX/Linux:

macOS:

$ /usr/local/opt/llvm/bin/clang++ -Wp,-v -x c++ - -fsyntax-only < /dev/null 2>&1 | grep -e /clang
 /usr/local/Cellar/llvm/6.0.1/lib/clang/6.0.1/include


Linux:
$ clang++ -Wp,-v -x c++ - -fsyntax-only < /dev/null 2>&1 | grep -e /clang
 /usr/local/lib/clang/6.0.0/include

torsdag 9 augusti 2012

Compile Time Hashes pt2

While waiting for Visual C++ to implement the C++11 features I wrote about in the previous entry, I wanted a solution that worked on windows. This time I needed to implement the hashlittle function found in lookup3.c.

I used template programming to get the size of the string at compile time and I also relied on the compilers to optimize the code into the final result.

You can download the final code here: hashlittle.zip
Update (2012-08-20): Fixed bug in function for edge cases where the string was a multiple of 12 (doh!)

torsdag 12 juli 2012

Compile time hashes

C++11

Recently I’ve seen more and more of the C++11 features in the code reviews I oversee, so I needed to read up on the details. Some of the features were already featured in the C++0X standard, which has been semi-supported for some time now.


The second link will give you a hint of what’s supported for various compilers. Unfortunately, no current compiler supports C++11 entirely. And as usual it’s that MSVS is the farthest behind the standard.

The resulting files have been zipped together for your convenience: mm3hash.zip