简体   繁体   English

在C ++中编写自定义编译命令时的快捷方式。

[英]Shortcut when writing a custom compile command in c++.

I am trying to run a custom c++ file so that it can link to Matlab and do the plotting. 我试图运行一个自定义的c ++文件,以便它可以链接到Matlab并进行绘图。 So far, my command in terminal to compile the .cpp file is as follow: 到目前为止,我在终端中编译.cpp文件的命令如下:

g++ inputfile.cpp -o outoutfile -I/usr/local/MATLAB/R2017a/extern/include -L/usr/local/MATLAB/R2017a/bin/glnxa64 -leng -lmx -lm -lmat -lut -lstdc++

The outputfile is then ran as: 然后将输出文件运行为:

./outputfile

Question is: Is there a shortcut so that I dont have to type out the path to include and links every time? 问题是:有没有捷径可让我不必每次都键入要包含和链接的路径?

Please help, thanks. 请帮忙,谢谢。

P/S. P / S。 I am currently on a Ubuntu machine, and I really do not want to go the IDE route (Visual Studio, CodeBlocks,.. etc.). 我目前在Ubuntu机器上,我真的不想走IDE路线(Visual Studio,CodeBlocks等)。 I just want to code in a simple text editor, with terminal open to compile and run. 我只想在一个简单的文本编辑器中编写代码,并打开终端进行编译和运行。

So far, I have tried 2 approaches: the 1st one is to have a text editor, a terminal and I manually enter the compile (with linked library syntax). 到目前为止,我已经尝试了两种方法:第一种是使用文本编辑器,终端,然后手动输入编译(使用链接库语法)。 This works every time but I got tired of writing the syntax all the time. 每次都可以使用,但是我一直都在厌倦编写语法。

The 2nd approach is to use Sublime Text, I have made a custom built. 第二种方法是使用Sublime Text,我已经进行了自定义构建。 This works half of the time. 这有一半的时间有效。

The standard approach is to prepare Makefile and setup required goals there. 标准方法是准备Makefile并在那里设置所需的目标。 Then you would just run something like: 然后,您将只运行以下内容:

make outputfile
./outputfile

This answer has a very good introduction into the simple makefile. 这个答案对简单的makefile有很好的介绍。

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

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