「Eclipse」- C/C++(CDT)

  CREATED BY JENKINSBOT

问题描述

该笔记将记录:在 Eclipse 中,如何使用 CDT 进行 C 语言开发,以及常见问题的解决方法;

解决方案

CDT/User/FAQ – Eclipsepedia

常见问题处理

修改 includes 路径

Adding Include paths and symbols

1)right-click the project and select Properties
2)C/C++ General ⇒ Paths and Symbols ⇒ Includes ⇒ Add…

补充说明:
1)对于使用其他版本内核头文件,应该选择 /include/ 目录下;
2)还能够针对特定源码文件选择其头文件;

代码格式化

c – Eclipse C99 struct initialization formatting – Stack Overflow
Eclipse code style formatter: How to keep closing braces of initializer list in seperate line?

调整数组花括号的结构:
0)Windows -> Preferences -> C/C++ -> Code Style -> Formatter ⇒ Edit…
1)Under the tab Line Wrapping there is an option Initializer list which should apply to traditional initializer lists as well as C99 designated initializers.
2)Under the tab Braces there is another option Initializer list which you like to set to Next line indented.

如果想将数组闭合的花括号调整到下一行,需要 Export… 配置文件,并手动修改如下属性,再导入:

"org.eclipse.cdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="insert"

// 如下为调整后的效果
int array[] = {
        1,
        16,
        17
};

转化项目

Eclipse C/C++ Development Guide (Galileo) – Converting a C or C++ nature for a project

1)Click File > New > Other.
2)Click C or C++.
3)Click Convert to C/C++ Make Project.
4)Click Next.
5)In the Candidates for conversion list, select the projects to convert.
6)In the Convert to C or C++ box, click C Project or C++ Project.
7)Click Finish.

自动引入

运行项目

How to install and use Eclipse CDT for C/C++ programming

1)right-click on the “<Project>” (or anywhere on the source “test.cpp”, or select the “Run” menu)
2)Run As ⇒ Local C/C++ Application
3)The output “Hello, world!” appears on the “Console” panel.