c++ - := versus = error: undefined reference to qMain(int, 字符**)

标签 c++ windows qt makefile

Qt 4.6.1

在下面的.pro文件中,当我使用该语句时

sources = ef.cpp

我收到以下错误:

RInside.h: No such file or directory

enter image description here

然后当我用 := 替换 = 时:

sources := ef.cpp

上述错误消失,并且我收到一个新错误:

error: undefined reference to qMain(int, char**)

enter image description here

从这里:https://stackoverflow.com/a/448939/462608

VARIABLE = value Normal setting of a variable - values within it are recursively expanded when the variable is used, not when it's declared

VARIABLE := value Setting of a variable with simple expansion of the values inside - values within it are expanded at declaration time.

我想了解这里发生了什么以及解决方案是什么。

.cpp

#include <RInside.h>
int main(int argc, char *argv[]) 
{
    RInside R(argc, argv);

    R["txt"] = "Hello, world!\n";

    R.parseEvalQ ("cat(txt)");

    exit(0);
}

.pro

TEMPLATE    = app
TARGET      = 
DEPENDPATH  += .
INCLUDEPATH += .

R_HOME  := 'c:/R-2.15.1'

# Input
sources  = ef.cpp
programs := $(sources:.cpp=)

## include headers and libraries for R
RCPPFLAGS :=        $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config --cppflags)
RLDFLAGS  :=        $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config --ldflags)
RBLAS     :=        $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config BLAS_LIBS)
RLAPACK   :=        $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config LAPACK_LIBS)

## include headers and libraries for Rcpp interface classes
RCPPINCL  :=        $(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R $(R_ARCH) --vanilla 

--slave)
RCPPLIBS  :=        $(shell echo 'Rcpp:::LdFlags()'  | $(R_HOME)/bin/R $(R_ARCH) --vanilla --slave)


## include headers and libraries for RInside embedding classes
RINSIDEINCL :=      $(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R $(R_ARCH) --vanilla --slave)
RINSIDELIBS :=      $(shell echo 'RInside:::LdFlags()'  | $(R_HOME)/bin/R $(R_ARCH) --vanilla --slave)


## compiler etc settings used in default make rules
CXX        := $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config CXX)
CPPFLAGS   := -Wall $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config CPPFLAGS)
#CXXFLAGS  := $(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL) $(shell $(R_HOME)/bin/R $(R_ARCH) 

CMD config CXXFLAGS)
QMAKE_CXXFLAGS := $(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL) $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config CXXFLAGS)
LDFLAGS    = -s
QMAKE_LIBS := $(RLDFLAGS) $(RBLAS) $(RLAPACK) $(RINSIDELIBS) $(RCPPLIBS)
CC         := $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config CXX)

最佳答案

这看起来不像 Qt 项目,因此您可能应该禁用针对 Qt 库的链接。将QTCONFIG设置为空:

QT =
CONFIG =

如果另一方面,这是一个应该链接到 Qt 库的 Qt 项目,那么问题就在于您正在覆盖重要变量,例如 QMAKE_LIBSQMAKE_CXXFLAGS。使用+=,而不是:=。另外,请使用LIBS,而不是QMAKE_LIBS

关于c++ - := versus = error: undefined reference to qMain(int, 字符**),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13171263/

相关文章:

c++ - 通过引用将对象传递给函数不会更改此对象

c++ - 模拟矩阵背景

c++ - 使用 Howard Hinnant 的 date.h 计算某个日期今年的天数

windows - @Transactional 和 JerseyTest 在 Linux 或 Mac 上的问题,但在 Windows 上没有

windows - PhoneGap错误: EPERM: Operation not permitted (windows 10)

c++ - 为什么我不能用谓词的实例化构造 std::set,但我可以分配以这种方式构造的 std::set?

windows - 在 Windows 服务器上部署 Socket.io

自定义 Qt 类的 CSS 选择器

c++ - 在堆栈上分配和从函数返回 QSharedPointer

c++ - 在Qt/C++中通过光标选择一个单词并获取它的位置