0

I have built a static library on Linux with gcc compilers using cmake and am now porting to windows with msvc compilers. I'm using CLion with the default generator, which is NMakefiles x64. I have managed to get my library to build without errors, but when I try to run any code from the library, the program just crashes. In attempt to debug I'm using dumpbin.exe to find the names of functoins that are missing in the COFF table.

> dumpbin /symbols .\redland-combined.lib | findstr "UNDEF"

gives me a long list of UNDEF symbols. Here's an excerpt

...
093 00000000 UNDEF  notype       External     | raptor_xml_namespace_uri
012 00000000 UNDEF  notype ()    External     | free
013 00000000 UNDEF  notype ()    External     | malloc
014 00000000 UNDEF  notype ()    External     | raptor_namespaces_start_namespace
015 00000000 UNDEF  notype ()    External     | raptor_new_namespace
018 00000000 UNDEF  notype ()    External     | raptor_librdfa_rdfa_iri_get_base
01A 00000000 UNDEF  notype ()    External     | raptor_librdfa_rdfa_create_mapping
01B 00000000 UNDEF  notype ()    External     | raptor_librdfa_rdfa_copy_mapping
01C 00000000 UNDEF  notype ()    External     | raptor_librdfa_rdfa_update_mapping
01D 00000000 UNDEF  notype ()    External     | raptor_librdfa_rdfa_free_mapping
01E 00000000 UNDEF  notype ()    External     | raptor_librdfa_rdfa_create_list
01F 00000000 UNDEF  notype ()    External     | raptor_librdfa_rdfa_replace_list
020 00000000 UNDEF  notype ()    External     | raptor_librdfa_rdfa_pop_item
021 00000000 UNDEF  notype ()    External     | raptor_librdfa_rdfa_free_list
022 00000000 UNDEF  notype ()    External     | raptor_librdfa_rdfa_replace_string
026 00000000 UNDEF  notype ()    External     | memset

Some of the symbols listed are a part of the library I'm tryng to build while others are from dependency libraries. All of this confuses me because I've double and triple checked that the include paths and link libraries are accurate - besides, shouldn't we get a compile/linker error if these were inaccurate? What I'm most confused about is the presence of the likes of malloc and free in there. What do I need to do to convert the label here in this table for malloc from EXTERNAL to STATIC?

CiaranWelsh
  • 7,014
  • 10
  • 53
  • 106
  • 1
    Static library doesn't get linked - it's just a collection of .obj files. Dependencies are resolved when the actual binary (EXE or DLL) is linked with all the static libraries. It is perfectly normal and expected for standard C library functions like `malloc` to be external dependencies of a static library. To the extent there is a problem, it lies elsewhere. – Igor Tandetnik Jun 21 '20 at 16:46
  • I was using `dumpbin` as a kind of parallel to Unix's `nm lib.a | grep "function"`. It turns out this is fundamentally the wrong approach since it appears the `*.a` isn't an analogue of `*.lib`. My problem was that I thought I was statically linking to my external dependencies. After copying them all into the same directory my program was able to run. – CiaranWelsh Jun 21 '20 at 17:44

0 Answers0