也许这是在某处回答了,我只是不知道这个词来搜索。 我想,如果我不明白减号来理解,如果我看到一个bug或。 在头从而使编译器在跳闸不断的分配“ - ”?
我的项目具有以下结构,包括生成的文件:
test ├── src │ ├── TipCoordinate.cpp │ └── TipCoordinate.hpp └── UnitTest ├── main.cpp ├── main.o ├── Makefile ├── TipCoordinate.o ├── UnitTest.pro └── UnitTest.pro.user
我在我的类头定义的常数如下:
class TipCoordinate{
public:
TipCoordinate() {};
~TipCoordinate() {};
void Z(const float z);
private:
static const float sREFERENCE_SPHERE_RADIUS = 12;
};
在我班上的cpp文件下面的代码不会编译:
#include "TipCoordinate.hpp"
void TipCoordinate::Z(const float z){
float z_origin_ = -sREFERENCE_SPHERE_RADIUS;
}
我收到错误.../model/TipCoordinate.cpp:143: error: undefined reference to 'TipCoordinate::sREFERENCE_SPHERE_RADIUS'
但是,如果我只是改变它,如下所示那么它是完全幸福:
#include "TipCoordinate.hpp"
void TipCoordinate::Z(const float z){
float z_origin_ = -1*sREFERENCE_SPHERE_RADIUS;
}
另外,该作品也:
#include "TipCoordinate.hpp"
void TipCoordinate::Z(const float z){
float z_origin_ = 0-sREFERENCE_SPHERE_RADIUS;
}
我认为亚当罗森菲尔德的回答解决了我的问题,但在应对一些评论我更换了能重现问题最小的,完整的例子上面摘录。 正如一些猜测,我使用G ++。 该版本是G ++(Ubuntu的/ Linaro的4.5.2-8ubuntu4)4.5.2,它很可能是优化的影响,因为我使用“Qt Creator的2.1.0,基于Qt 4.7.2(32位),建于2011" 年3月11日。 这里是我的项目文件:
QT -= gui
INCLUDEPATH += ../src
TEMPLATE = app
SOURCES += main.cpp \
../src/TipCoordinate.cpp
HEADERS += \
../src/TipCoordinate.hpp
我的主要文件只是以下,但改变的项目模板库和消除主文件导致该问题消失。
int main() { return 0; }
我怀疑,Qt Creator中很重要,因为除了更改模板,当我改变其他看似风马牛不相及的因素问题消失或再次出现。 出于这个原因,我已经包括了Qt Creator中产生的Makefile如下:
#############################################################################
# Makefile for building: UnitTest
# Generated by qmake (2.01a) (Qt 4.7.3) on: Sun Oct 14 15:05:23 2012
# Project: UnitTest.pro
# Template: app
# Command: /usr/local/Trolltech/QtEmbedded-4.7.3/bin/qmake -spec /usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/qws/linux-x86-g++ CONFIG+=debug QMLJSDEBUGGER_PATH=/usr/share/qtcreator/qml/qmljsdebugger -o Makefile UnitTest.pro
#############################################################################
####### Compiler, tools and options
CC = gcc
CXX = g++
DEFINES = -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED
CFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
CXXFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
INCPATH = -I/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/qws/linux-x86-g++ -I. -I/usr/local/Trolltech/QtEmbedded-4.7.3/include/QtCore -I/usr/local/Trolltech/QtEmbedded-4.7.3/include/QtNetwork -I/usr/local/Trolltech/QtEmbedded-4.7.3/include -I../src -I.
LINK = g++
LFLAGS = -Wl,-rpath,/usr/local/Trolltech/QtEmbedded-4.7.3/lib
LIBS = $(SUBLIBS) -L/usr/local/Trolltech/QtEmbedded-4.7.3/lib -lQtNetwork -L/usr/local/Trolltech/QtEmbedded-4.7.3/lib -lQtCore -lpthread
AR = ar cqs
RANLIB =
QMAKE = /usr/local/Trolltech/QtEmbedded-4.7.3/bin/qmake
TAR = tar -cf
COMPRESS = gzip -9f
COPY = cp -f
SED = sed
COPY_FILE = $(COPY)
COPY_DIR = $(COPY) -r
STRIP = strip
INSTALL_FILE = install -m 644 -p
INSTALL_DIR = $(COPY_DIR)
INSTALL_PROGRAM = install -m 755 -p
DEL_FILE = rm -f
SYMLINK = ln -f -s
DEL_DIR = rmdir
MOVE = mv -f
CHK_DIR_EXISTS= test -d
MKDIR = mkdir -p
####### Output directory
OBJECTS_DIR = ./
####### Files
SOURCES = main.cpp \
../src/TipCoordinate.cpp
OBJECTS = main.o \
TipCoordinate.o
DIST = /usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/common/g++.conf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/common/unix.conf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/common/linux.conf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/common/qws.conf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/qconfig.pri \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/modules/qt_webkit_version.pri \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/qt_functions.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/qt_config.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/exclusive_builds.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/default_pre.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/debug.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/default_post.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/warn_on.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/qt.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/unix/thread.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/moc.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/resources.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/uic.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/yacc.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/lex.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/include_source_dir.prf \
UnitTest.pro
QMAKE_TARGET = UnitTest
DESTDIR =
TARGET = UnitTest
first: all
####### Implicit rules
.SUFFIXES: .o .c .cpp .cc .cxx .C
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.cc.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.cxx.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.C.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.c.o:
$(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"
####### Build rules
all: Makefile $(TARGET)
$(TARGET): $(OBJECTS)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
Makefile: UnitTest.pro /usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/qws/linux-x86-g++/qmake.conf /usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/common/g++.conf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/common/unix.conf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/common/linux.conf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/common/qws.conf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/qconfig.pri \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/modules/qt_webkit_version.pri \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/qt_functions.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/qt_config.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/exclusive_builds.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/default_pre.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/debug.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/default_post.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/warn_on.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/qt.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/unix/thread.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/moc.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/resources.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/uic.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/yacc.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/lex.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/include_source_dir.prf \
/usr/local/Trolltech/QtEmbedded-4.7.3/lib/libQtNetwork.prl \
/usr/local/Trolltech/QtEmbedded-4.7.3/lib/libQtCore.prl
$(QMAKE) -spec /usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/qws/linux-x86-g++ CONFIG+=debug QMLJSDEBUGGER_PATH=/usr/share/qtcreator/qml/qmljsdebugger -o Makefile UnitTest.pro
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/common/g++.conf:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/common/unix.conf:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/common/linux.conf:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/common/qws.conf:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/qconfig.pri:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/modules/qt_webkit_version.pri:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/qt_functions.prf:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/qt_config.prf:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/exclusive_builds.prf:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/default_pre.prf:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/debug.prf:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/default_post.prf:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/warn_on.prf:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/qt.prf:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/unix/thread.prf:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/moc.prf:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/resources.prf:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/uic.prf:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/yacc.prf:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/lex.prf:
/usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/features/include_source_dir.prf:
/usr/local/Trolltech/QtEmbedded-4.7.3/lib/libQtNetwork.prl:
/usr/local/Trolltech/QtEmbedded-4.7.3/lib/libQtCore.prl:
qmake: FORCE
@$(QMAKE) -spec /usr/local/Trolltech/QtEmbedded-4.7.3/mkspecs/qws/linux-x86-g++ CONFIG+=debug QMLJSDEBUGGER_PATH=/usr/share/qtcreator/qml/qmljsdebugger -o Makefile UnitTest.pro
dist:
@$(CHK_DIR_EXISTS) .tmp/UnitTest1.0.0 || $(MKDIR) .tmp/UnitTest1.0.0
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/UnitTest1.0.0/ && $(COPY_FILE) --parents ../src/TipCoordinate.hpp .tmp/UnitTest1.0.0/ && $(COPY_FILE) --parents main.cpp ../src/TipCoordinate.cpp .tmp/UnitTest1.0.0/ && (cd `dirname .tmp/UnitTest1.0.0` && $(TAR) UnitTest1.0.0.tar UnitTest1.0.0 && $(COMPRESS) UnitTest1.0.0.tar) && $(MOVE) `dirname .tmp/UnitTest1.0.0`/UnitTest1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/UnitTest1.0.0
clean:compiler_clean
-$(DEL_FILE) $(OBJECTS)
-$(DEL_FILE) *~ core *.core
####### Sub-libraries
distclean: clean
-$(DEL_FILE) $(TARGET)
-$(DEL_FILE) Makefile
check: first
mocclean: compiler_moc_header_clean compiler_moc_source_clean
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
compiler_moc_header_make_all:
compiler_moc_header_clean:
compiler_rcc_make_all:
compiler_rcc_clean:
compiler_image_collection_make_all: qmake_image_collection.cpp
compiler_image_collection_clean:
-$(DEL_FILE) qmake_image_collection.cpp
compiler_moc_source_make_all:
compiler_moc_source_clean:
compiler_uic_make_all:
compiler_uic_clean:
compiler_yacc_decl_make_all:
compiler_yacc_decl_clean:
compiler_yacc_impl_make_all:
compiler_yacc_impl_clean:
compiler_lex_make_all:
compiler_lex_clean:
compiler_clean:
####### Compile
main.o: main.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
TipCoordinate.o: ../src/TipCoordinate.cpp ../src/TipCoordinate.hpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o TipCoordinate.o ../src/TipCoordinate.cpp
####### Install
install: FORCE
uninstall: FORCE
FORCE:
我看到一个滚动框出现,但如果有一种方法,使显示更简洁,我欢迎任何提示。