[英]How can I get C++ code that compiles via terminal to compile using the Qt IDE?
My general question is how can I get C++ code that compiles when I issue我的一般问题是如何获得在我发出时编译的 C++ 代码
g++ <my_program>.cpp -o my_program -O3 -ffast-math -lm -llapack -lgsl -lgslcblas
to build using the Qt IDE. The C++ code I have is written by my physics advisor and is for research that I'm conducting under his guidance, and I would like to be able to use a visual environment for changes I have to make.使用 Qt IDE 进行构建。我的 C++ 代码是由我的物理顾问编写的,用于我在他的指导下进行的研究,我希望能够使用可视化环境进行更改。 At the moment, my specific issue is (outside of the hundreds of warnings) one of the header files references several lapacke library functions that cause an "undefined reference" error.
目前,我的具体问题是(在数百个警告之外)header 文件之一引用了几个导致“未定义引用”错误的 lapacke 库函数。 The offending line is:
违规行是:
template <>
int tensor<double>::find_eigenvalues()
{
// some code
// for loop
{
dsyevr_ (&JOBZ, &RANGE, &UPLO, &SIZE, A, &SIZE, &VLU, &VLU, &ILU, &ILU, &ABSTOL, &M,
(double *)(obj->eval), Z, &LDZ, ISUPPZ, WORK, &LWORK, IWORK, &LIWORK, &INFO) ;
}
// more code
}
Above this function definition appears上面这个function定义出现
extern "C" void dsyevr_ (char *, char *, char *, int *, double *, int *, double *, double *,
int *, int *, double *, int *, double *, double *, int *, int *,
double *, int *, int *, int *, int *) ;
Now, if I explicitly include the lapacke header file #include "lapacke.h"
I can get rid of that error.现在,如果我明确包含 lapacke header 文件
#include "lapacke.h"
,我就可以消除该错误。 However, a new one pops up.然而,一个新的弹出。 I get a "conflicting type" error from the line
我从该行收到“冲突类型”错误
extern "C" void zheevr_ (char *, char *, char *, int *, complex *, int *, double *, double *, int *, int *, double *, int *, double *,
complex *, int *, int *, complex *, int *, double *, int *, int *, int *, int *) ;
which is also a function that is defined in the lapacke.h header file.这也是在 lapacke.h header 文件中定义的 function。 Any help is appreciated!
任何帮助表示赞赏!
My coding level would be school taught, but over 20 years since I've had a course in C++. I'm ok with basic notions, though.我的编码水平是学校教的,但自从我在 C++ 上过一门课程以来已有 20 多年了。不过我对基本概念没问题。
My version of Linux is: Ubuntu 18.04.5 x86_64.我的Linux版本是:Ubuntu 18.04.5 x86_64。 The g++ compiler version is: g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0;
g++编译版本为:g++(Ubuntu 7.5.0-3ubuntu1~18.04)7.5.0; which is also the kit I have selected for Qt.
这也是我为 Qt 选择的套件。
I would strongly advise you to use CMake ( https://cmake.org/ ) to compile your project instead of using direct calls to the compiler.我强烈建议您使用CMake ( https://cmake.org/ ) 来编译您的项目,而不是直接调用编译器。 Using CMake will make it compatible with the QtCreator IDE while keeping it compilable through a command line as well.
使用CMake 将使其与 QtCreator IDE 兼容,同时保持其可通过命令行进行编译。 CMake also manages dependencies such as your external libraries and is the most widely used build tool for C++. You can find many example to help you getting started if needed.
CMake 还管理外部库等依赖项,是 C++ 使用最广泛的构建工具。如果需要,您可以找到许多示例来帮助您入门。 There are other build tools compatible with QtCreator, such as QMake or Qbs, but both are (unfortunately) less used than CMake.
还有其他与 QtCreator 兼容的构建工具,例如 QMake 或 Qbs,但两者(不幸的是)都比 CMake 使用得少。
For your specific linking issue, you might need to add a -L option to locate your library file.对于您的特定链接问题,您可能需要添加一个 -L 选项来定位您的库文件。 (-L for the lib path, -l for the lib name).
(-L 为 lib 路径,-l 为 lib 名称)。
In CMake, the commands that will interest you specifically are:在CMake中,你会特别感兴趣的命令是:
add_executable(..)
target_link_libraries(..)
target_include_directories(..)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.