简体   繁体   English

如何让Geany与C中的数学库链接?

[英]How to get Geany to link with the math library in C?

I'm using the Linux Mint distribution, and writing a program in C. However, I'm having trouble with the compilation part. 我正在使用Linux Mint发行版,并使用C语言编写程序。但是,我在编译部分遇到了麻烦。 Specifically, none of the math.h functions seem to work (like sqrt() or pow()). 具体来说,所有math.h函数似乎都不起作用(例如sqrt()或pow())。

I know that if I were compiling through the terminal I would have to link it myself by adding the -lm part at the end of the command. 我知道,如果要通过终端进行编译,则必须在命令末尾添加-lm部分来自己链接该终端。 But is there a way to do it through Geany? 但是有办法通过Geany做到吗? Or do I have to do it manually? 还是我必须手动进行?

under the geany 'build' menu item is the selection: Set Build Commands 在geany'build'菜单项下是以下选择: Set Build Commands

after clicking build then Set Build Commands the Set Build Commands window opens. 点击后build ,然后Set Build CommandsSet Build Commands窗口中打开。

under the first column is label under that is Compile to the right of Compile is a text box where you type the compile command. 第一栏下是label下是Compile到右侧的Compile是你在那里输入编译命令文本框。

ON my system, the contents of the compile text box is: 在我的系统上,编译文本框的内容为:

gcc -ggdb  -Wall -Wextra  -Wconversion -std=gnu11 -pedantic -Wmissing-prototypes  -c "%f"  -I. 

the next line down is labeled Build to the right of the Build is a text box where you type the link command. 下一行向下标记Build到右侧Build是你键入链接命令文本框。

On my system, the contents of the build text box is: 在我的系统上,构建文本框的内容为:

gcc -ggdb  -Wall -Wextra -Wconversion -std=gnu11 -pedantic -o "%e" "%f"   -lpthread -lm  

(actual contents will vary for special needs) (实际内容因特殊需要而异)

Notice, at the END of the Build text box are the library items to be included. 注意,在“ Build文本框的末尾是要包含的库项目。 Amongst those libraries is the libm.so (which is written without the lib and without the so .) IE -lm 那些库中有libm.so (它是在没有libso情况下编写的)IE -lm

That is all that is needed to compile and link 'many/most' programs. 这就是编译和链接“许多/大多数”程序所需的全部。

Note: the parameter -ggdb is to have the compile and link steps include all the debug information for the gdb debugger 注意:参数-ggdb将具有编译和链接步骤,包括gdb调试器的所有调试信息。

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

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