C-library not linking using gcc/g++

后端 未结 3 1131
终归单人心
终归单人心 2020-12-28 15:19

I have a c-library which I use in gcc. The library has the extension .lib but is always linked as a static library. If i write a program which uses the library as c-code, ev

3条回答
  •  滥情空心
    2020-12-28 16:03

    The C++ compiler performs what is known as name-mangling - the names that appear in your code are not the same ones as your linker sees. The normal way round this is to tell the compiler that certain functions need C linkage:

    // myfile.cpp
    extern "C" int libfun();    // C function in your library
    

    or do it for a whole header file:

    // myfile.cpp
    extern "C" {
      #include "mylibdefs.h"      // defs for your C library functions
    }
    

提交回复
热议问题