Tag: c++

GHC and C++

Recently I was getting error messages from GHC while building Haskell programs that complain about unknown symbols referring to C++ standard template library symbols. It turns out that these are weak symbols (since only one definition is required) and telling ghc to pass the extra (forbidden, deprecated, and evil) -fno-weak flag to gcc helps. I guess I am in trouble when this flag is finally removed. After changing this, the compiler complained that it could not find libstdc++.so. A ghc bug de…

C++ Calling Conventions

My advisor presented me with an interesting problem the other day. Calling some simple C++ free functions that took C++ objects by value using Python's ctypes produced strange results. We eventually narrowed the test case down to the following: 1#include <stdio.h> 2 3struct Simple { 4 int x,y,z; 5}; 6 7struct Fancy { 8 int x,y,z; 9 ~Fancy() { 10 printf("Destroying a Fancy\n"); 11 } 12}; 13 14extern "C" { 15 void printSimple(Simple s) { 16 fprintf(stderr, &qu…