简体   繁体   English

如何使C ++库在Eclipse中工作?

[英]How do you get C++ libraries to work in Eclipse?

I'm not gonna waste too much time moaning about how difficult it is coming from Java, a language where you quite literally click a button and select a file to add external libraries to a project, to C++ where it seems impossible to do without the patience of an owl. 我不会浪费太多时间抱怨Java带来的困难,Java是一种语言,您只需单击一个按钮并选择一个文件即可将外部库添加到项目中,而C ++似乎无法做到这一点。猫头鹰的耐心。 I didn't think I'd ever have to post a question like this since it seemed quite elementary but it's been at least 3 weeks of trying and failing. 我认为我根本不必发布这样的问题,因为它看起来很基础,但经过至少三周的尝试和失败。 I've also read the vague documentation provided by the eclipse website and it doesn't really cover anything at all. 我还阅读了eclipse网站提供的模糊文档,但实际上并没有涵盖任何内容。

For example, let's say gtkmm-3.0. 例如,假设gtkmm-3.0。 I have installed that on my linux machine and everything is fine. 我已经在我的linux机器上安装了它,一切都很好。 Why isn't it possible to just do: 为什么不可能只做:

 #include <gtkmm-3.0/gtkmm.h>

since that does come up as a suggestion in Eclipse. 因为这确实是Eclipse中的建议。 At this stage, I'm already at a loss since I think a good IDE shouldn't give suggestions for things that aren't actually usable and if it does,it should at least automatically include them or something. 在这个阶段,我已经茫然了,因为我认为一个好的IDE不应为实际上不可用的东西提供建议,如果可以的话,它应该至少自动包括这些东西。

I have also tried and failed many times with other libraries and asked for help from a full-time C++ developer that I know and he couldn't work his head around the error either. 我在其他库中也尝试过很多次,但失败了很多,并向我认识的专职C ++开发人员寻求帮助,他也无法解决该错误。

tl;dr - Download lib off internet, open eclipse, what do? tl; dr-从Internet下载lib,打开eclipse,该怎么办?

Sorry if this question seems silly. 抱歉,这个问题似乎很愚蠢。 The depression is honestly just.. terrible when 'working' with C++. 老实说,这种沮丧是..当与C ++“一起工作”时,这是可怕的。

The best way I have found for including and linking against the appropriate libraries has been to create build variables for all configurations. 我发现包含和链接适当库的最好方法是为所有配置创建构建变量。 This way I can have one place where I add/remove libraries and flags as needed. 这样,我可以在一个地方根据需要添加/删除库和标志。

  • Create your build variables 创建您的构建变量
    • Right click your project and select properties then C/C++ Build -> Build Varialbes 右键单击您的项目,然后选择属性,然后选择C / C ++ Build-> Build Varialbes
    • Make sure that configuration is set to [All Configurations] 确保将配置设置为[All Configurations]
    • Select add and give it a name like GTK_CFLAGS and for the value, it is a string of the type `pkg-config gtkmm-3.0 --cflags`(those are back ticks) 选择add并给它一个名称,如GTK_CFLAGS并为其指定值,它是类型为`pkg-config gtkmm-3.0 --cflags`的字符串(那些是反勾号)
    • Now do another variable but name it GTK_LIBS and use the flag --libs instead of --cflags . 现在执行另一个变量,但将其命名为GTK_LIBS并使用--libs而不是--cflags标志。
    • Select Apply 选择应用
  • Now Go to Settings(should be under C/C++ build as well) 现在转到“设置”(也应在C / C ++构建下)
    • Make sure that configuration is for all configurations and not just release or debug 确保该配置适用于所有配置,而不仅仅是发布或调试
    • Select GCC C++ Compiler (or whatever compiler you are using) 选择GCC C++ Compiler (或您使用的任何编译器)
    • In the command line pattern (should look something like ${COMMAND} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} -std=c++11 ) add ${GTK_CFLAGS} (or whatever you called it) after the command macro 在命令行模式中(应该类似于${COMMAND} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} -std=c++11 ),添加${GTK_CFLAGS} (或其他任何值)您调用它)在命令宏之后
    • select apply 选择申请
    • Now Select GCC C++ Linker and in the command line pattern after ${INPUTS} put ${GTK_LIBS} and select apply 现在选择GCC C++ Linker ,在${INPUTS}之后的命令行模式中,放入${GTK_LIBS}并选择${GTK_LIBS}

This should let you compile with GTKmm, there may still be issues with the indexer and autocomplete. 这应该使您可以使用GTKmm进行编译,但索引器和自动完成可能仍然存在问题。 If you want to include specific header files so that your indexer and autocomplete can seen them. 如果要包括特定的头文件,以便索引器和自动完成功能可以看到它们。 You can do that in C/C++ General-> Paths and Symbols and add the include directory and then select apply and rebuild your index. 您可以在C/C++ General-> Paths and Symbols并添加包含目录,然后选择应用并重建索引。

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

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