简体   繁体   English

C静态库与NetBeans的链接问题

[英]C Static Library linking problems with NetBeans

Hello stackoverflow community. 您好stackoverflow社区。 I have been trying to teach myself static and dynamic libraries in C. I am having an issue though. 我一直在尝试自学C语言中的静态和动态库。不过,我遇到了一个问题。 My linking does not appear to be working at all. 我的链接似乎根本没有用。 I made a simple testing static library. 我做了一个简单的测试静态库。 Here is the code for the .c file: 这是.c文件的代码:

#include <stdio.h>

void test(char * c)
{
    printf(c);
}

And the .h file: 和.h文件:

#ifndef TEST_H
#define TEST_H

#ifdef  __cplusplus
extern "C" {
#endif




#ifdef  __cplusplus
}
#endif

extern void test(char * c);

#endif  /* TEST_H */

Here are the steps I take to produce the issue. 这是我要解决此问题的步骤。

First, I build this static library project with NetBeans, which generates a .a library (I am using MinGW for compiling). 首先,我使用NetBeans构建此静态库项目,该项目将生成一个.a库(我正在使用MinGW进行编译)。

Then, I copy the .a file, as well as the library's .h file into a folder. 然后,将.a文件以及库的.h文件复制到文件夹中。

I then start a new C/C++ application project in NetBeans. 然后,我在NetBeans中启动一个新的C / C ++应用程序项目。 I right click this project, and click properties. 我右键单击该项目,然后单击属性。 Then I go to the Build tab, and within that, the Linker tab. 然后,我转到“构建”选项卡,在其中找到“链接器”选项卡。 This is the part I am having troubles with. 这是我遇到麻烦的部分。 No matter what I link, NetBeans acts as if I have linked nothing. 不管我链接什么,NetBeans的行为就像我什么都没有链接。 I have tried linking with "Additional Library Directories" and "Libraries". 我尝试与“其他图书馆目录”和“图书馆”链接。 Neither have worked. 都没有工作。 I have even tried manually reparsing the file by right clicking the project, going to the code assistance menu option, and clicking Reparse Project. 我什至尝试通过右键单击项目,转到代码帮助菜单选项,然后单击“重新分析项目”来手动重新分析文件。

Any help on figuring out what is wrong would be appreciated, thanks. 感谢您提供任何解决问题的帮助。

It appears that I forgot to link the library directory under build. 看来我忘记了链接正在构建的库目录。 To do this, I went to the project properties, the Build Tab, and the C Compiler tab, and then went to General, and added my library directory to "Include Directories and Headers". 为此,我转到了项目属性,“构建”选项卡和“ C编译器”选项卡,然后转到“常规”,并将我的库目录添加到“包含目录和标题”。

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

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