简体   繁体   English

g ++链接问题

[英]g++ linking issue

I have a dependancy library (libfcgi) that I compiled with g++ (GCC v4.4 MinGW) using the following calls: 我有一个依赖库(libfcgi),我使用以下调用用g ++(GCC v4.4 MinGW)进行了编译:

g++ -Iinclude -c -O2 *.c g ++ -Iinclude -c -O2 * .c
ar rcs ../libfcgi.a *.o ar rcs ../libfcgi.a * .o

Now, my main project is built like so: 现在,我的主要项目是这样构建的:

g++ -Idependancies\\libfcgi\\include -Ldependancies -O2 -lfcgi *.cpp g ++ -Idependancies \\ libfcgi \\ include -Ldependancies -O2 -lfcgi * .cpp

g++ apparently finds libfcgi.a, but yet it fails to link to the following references: g ++显然找到了libfcgi.a,但是它无法链接到以下参考:

'FCGI_printf' 'FCGI_printf'
'FCGI_Accept' 'FCGI_Accept'

In the libfcgi sources, these functions are defined as follows: 在libfcgi源文件中,这些函数的定义如下:

#ifdef __cplusplus
extern "C" {
#endif
//...
DLLAPI int FCGI_printf(const char *format, ...);  
DLLAPI int FCGI_Accept(void);
//...
#ifdef __cplusplus
}
#endif

where DLLAPI is nothing (as it isn't compiled as a shared library) and __cplusplus is defined (g++). 其中DLLAPI无效(因为它未编译为共享库),并且定义了__cplusplus(g ++)。

Looking at libfcgi.a, those functions are exported as '_FCGI_Accept' and '_FCGI_printf', so with an underscore in front. 查看libfcgi.a,这些函数将导出为'_FCGI_Accept'和'_FCGI_printf',因此前面带有下划线。 That's what seems to hinder g++ to find them. 那似乎阻碍了g ++找到它们。

I thought using export "C" would suffice to link to a C function in C++, so what am I doing wrong? 我认为使用export“ C”足以链接到C ++中的C函数,所以我在做什么错呢?

Thanks :) 谢谢 :)

如果您在.cpp源代码中具有相同的外部“ C”定义,那么我认为您的问题是-lfcgi应该在命令行中跟随* .cpp:

g++ -Idependancies\libfcgi\include -Ldependancies -O2 *.cpp -lfcgi

In your main-project, you tell the compiler to link C-functions, due to the extern "C" . 在主项目中,由于extern "C" ,您告诉编译器链接C函数。 It therefore expects unmangled symbol-names. 因此,它希望使用未修改的符号名称。 You should therefore compile the fcgi-library with the C compiler, not the C++ compiler. 因此,您应该使用C编译器而不是C ++编译器来编译fcgi-library。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM