Undefined refrences to '__imp' and '__cxa' when linking libraw

82 views Asked by At

I'm trying to link the c++ library, libraw, into my c program.

windows 10 msys2. Using clion, but also trying to compile from mingw64 terminal using gcc and clang

At first, I was using the version of libraw that i got from msys2 pacman. The issue is that the version in the repo is the latest release, but it is quite old and I need the beta release of libraw to support one of my newer cameras.

I've built the libraries from source (https://github.com/LibRaw/LibRaw) in mingw, and moved the libraw.a file, and .h files into the mingw64/lib and /include folder respectively, just as they appeared when added using pacman.

The issue is that now when I compile, a long list of errors is spit out including things such as undefined references to '__cxa'

I'm wondering what is causing these compile errors and what I can do to fix them, so that I can use libraw in my project. I assume it has something to do with how I'm compiling libraw, since using the version from pacman, the exact same c and cmake code works perfectly.

Here a simplified version of my c program (note that libtiff is working just fine, can can be ignored from the samples):

#include <stdio.h>
#include <tiffio.h>
#include <libraw.h>

int main(void);

int main(void)
{
    const char* libtiffVersion;
    const char* librawVersion;

    libtiffVersion = TIFFGetVersion();
    if(libtiffVersion)
        printf("%s\n", libtiffVersion);
    else
        printf("libtiff not found!\n");

    librawVersion = libraw_version();
    if(librawVersion)
        printf("%s\n", librawVersion);
    else
        printf("libraw not found!\n");

    return 0;
}

and my cmake (tried with various c standards from 90 to 23, although i don't think it mattres):

cmake_minimum_required(VERSION 3.23)
project(MyProject C)

set(CMAKE_C_STANDARD 90)

find_library(LIBRAW  libraw)
find_library(LIBTIFF libtiff)

add_executable(MyProject main.c)

target_link_libraries(MyProject ${LIBTIFF} ${LIBRAW})

The linker command generated by cmake is:

cmd.exe /C "cd . && C:\msys64\mingw64\bin\gcc.exe -g  CMakeFiles/MyProject.dir/main.c.obj -o MyProject.exe -Wl,--out-implib,libMyProject.dll.a -Wl,--major-image-version,0,--minor-image-version,0  C:/msys64/mingw64/lib/libtiff.dll.a  C:/msys64/mingw64/lib/libraw.a  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."

I read that what could be causing some of the issue, is that libraw is a c++ library (includes a c wrapper), while I'm trying to compile a c program, but trying to compile from the command line with g++, clang++, gcc with -lsupc++ with no luck. doing it this way gives me different errors, many of them including undefined reference to '__imp'

I've also tried copying the libraw.a file into my source directory compiling with a path to the .a file, with the no success.

I've tried using the binary release of the older version of libraw that I know was working, by copying the libraw.lib file to my source directory and changing my cmake file:


cmake_minimum_required(VERSION 3.23)
project(MyProject C)

set(CMAKE_C_STANDARD 90)

find_library(LIBTIFF libtiff)

add_executable(MyProject main.c)

target_link_libraries(MyProject ${LIBTIFF} ${PROJECT_SOURCE_DIR}/libraw.lib)

This time it compiles, but immediatly segfualts. Might have something to do with the binaries being built for windows using msvc while in using msys2/mingw64

0

There are 0 answers