未定义的引用(链接错误)

时间:2013-03-26 10:51:35

标签: c++ eclipse mingw

尝试编译cpp程序时遇到以下链接错误:

11:42:55 **** Incremental Build of configuration Debug for project mrconv ****
Info: Internal Builder is used for build
g++ "-IC:\\Users\\Jesse\\Documents\\Work\\Research\\FiberTracking\\Software\\mrtrix\\source\\mrtrix-0.2.11\\lib" "-IC:\\Users\\Jesse\\Programs\\gtk+\\lib" "-IC:\\Users\\Jesse\\Programs\\gtk+\\bin" "-IC:\\Users\\Jesse\\Programs\\gtk+\\include\\glib-2.0" "-IC:\\Users\\Jesse\\Programs\\gtk+\\lib\\glib-2.0\\include" "-IC:\\gtkmm64\\include\\glibmm-2.4\\glibmm" "-IC:\\gtkmm64\\include\\glibmm-2.4" "-IC:\\gtkmm64\\lib\\glibmm-2.4\\include" "-IC:\\gtkmm64\\include\\sigc++-2.0" "-IC:\\gtkmm64\\lib\\sigc++-2.0\\include" "-IC:\\Program Files (x86)\\GnuWin32\\include" "-IC:\\Program Files (x86)\\GnuWin32\\include\\gsl" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\mrconvert.o" "..\\src\\mrconvert.cpp" 
g++ "-LC:\\GnuWin32\\lib\\" -o mrconv.exe "src\\mrconvert.o" -llibgsl 
src\mrconvert.o: In function `main':
C:\Users\Jesse\workspace\mrconv\Debug/../src/mrconvert.cpp:119: undefined reference to `MR::App::run(int, char**)'
src\mrconvert.o: In function `ZN5MyApp7executeEv':
C:\Users\Jesse\workspace\mrconv\Debug/../src/mrconvert.cpp:123: undefined reference to `MR::parse_floats(std::string const&)'
C:\Users\Jesse\workspace\mrconv\Debug/../src/mrconvert.cpp:167: undefined reference to `MR::DataType::parse(std::string const&)'
C:\Users\Jesse\workspace\mrconv\Debug/../src/mrconvert.cpp:174: undefined reference to `MR::Image::parse_axes_specifier(MR::Image::Axes const&, std::string const&)'
C:\Users\Jesse\workspace\mrconv\Debug/../src/mrconvert.cpp:201: undefined reference to `MR::parse_ints(std::string const&, int)'
C:\Users\Jesse\workspace\mrconv\Debug/../src/mrconvert.cpp:225: undefined reference to `MR::ProgressBar::init(unsigned int, std::string const&)'
src\mrconvert.o: In function `_static_initialization_and_destruction_0':
C:\Users\Jesse\workspace\mrconv\Debug/../src/mrconvert.cpp:55: undefined reference to `MR::Argument::End'
C:\Users\Jesse\workspace\mrconv\Debug/../src/mrconvert.cpp:95: undefined reference to `MR::Option::End'
src\mrconvert.o: In function `ZNK2MR9Exception7displayEv':
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:187: undefined reference to `MR::Exception::level_offset'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:187: undefined reference to `MR::error'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:188: undefined reference to `MR::Exception::level_offset'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:188: undefined reference to `MR::info'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:189: undefined reference to `MR::debug'
src\mrconvert.o: In function `ZN2MR11ProgressBar3incEv':
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:451: undefined reference to `MR::ProgressBar::current_val'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:451: undefined reference to `MR::ProgressBar::current_val'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:452: undefined reference to `MR::ProgressBar::display'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:452: undefined reference to `MR::ProgressBar::stop'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:453: undefined reference to `MR::ProgressBar::multiplier'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:453: undefined reference to `MR::ProgressBar::stop_watch'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:453: undefined reference to `Glib::Timer::elapsed() const'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:453: undefined reference to `MR::ProgressBar::current_val'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:453: undefined reference to `MR::ProgressBar::multiplier'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:454: undefined reference to `MR::ProgressBar::percent'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:455: undefined reference to `MR::ProgressBar::percent'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:456: undefined reference to `MR::ProgressBar::display_func'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:458: undefined reference to `MR::ProgressBar::stop'
src\mrconvert.o: In function `ZN2MR11ProgressBar4doneEv':
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:461: undefined reference to `MR::ProgressBar::display'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/mrtrix.h:461: undefined reference to `MR::ProgressBar::done_func'
src\mrconvert.o: In function `ZN2MR5Image6ObjectD1Ev':
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/image/object.h:49: undefined reference to `MR::info'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/image/object.h:49: undefined reference to `MR::Image::Mapper::unmap(MR::Image::Header const&)'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/image/object.h:49: undefined reference to `MR::Image::Mapper::~Mapper()'
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/image/object.h:49: undefined reference to `MR::Image::Mapper::~Mapper()'
src\mrconvert.o: In function `ZN2MR5Image6Object3mapEv':
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/image/object.h:57: undefined reference to `MR::Image::Mapper::map(MR::Image::Header const&)'
src\mrconvert.o: In function `ZNK2MR7ArgBase9get_imageERNS_5Image6HeaderE':
C:/Users/Jesse/Documents/Work/Research/FiberTracking/Software/mrtrix/source/mrtrix-0.2.11/lib/args.h:201: undefined reference to `MR::Image::Object::create(std::string const&, MR::Image::Header&)'
src\mrconvert.o: In function `ZN5MyAppC1EiPPcPPKcPKN2MR8ArgumentEPKNS5_6OptionEPKjS3_S3_':
C:\Users\Jesse\workspace\mrconv\Debug/../src/mrconvert.cpp:119: undefined reference to `MR::App::App(int, char**, char const**, MR::Argument const*, MR::Option const*, unsigned int const*, char const*, char const*)'
src\mrconvert.o: In function `ZN5MyAppD1Ev':
C:\Users\Jesse\workspace\mrconv\Debug/../src/mrconvert.cpp:119: undefined reference to `MR::App::~App()'
collect2.exe: error: ld returned 1 exit status

11:42:57 Build Finished (took 1s.854ms)

看来这些是内部链接错误?我如何找到这些错误的来源?

2 个答案:

答案 0 :(得分:0)

您需要编译所有文件并将它们链接在一起。它要么缺少cpp文件或库

答案 1 :(得分:0)

这可能是问题所在。您需要使用-L来指定库文件的位置。 -I用于指定包含文件的位置。

g++ "-IC:\\Users\\Jesse\\Documents\\Work\\Research\\FiberTracking\\Software\\mrtrix\\source\\mrtrix-0.2.11\\lib" "-IC:\\Users\\Jesse\\Programs\\gtk+\\lib" "-IC:\\Users\\Jesse\\Programs\\gtk+\\bin" "-IC:\\Users\\Jesse\\Programs\\gtk+\\include\\glib-2.0" "-IC:\\Users\\Jesse\\Programs\\gtk+\\lib\\glib-2.0\\include" "-IC:\\gtkmm64\\include\\glibmm-2.4\\glibmm" "-IC:\\gtkmm64\\include\\glibmm-2.4" "-IC:\\gtkmm64\\lib\\glibmm-2.4\\include" "-IC:\\gtkmm64\\include\\sigc++-2.0" "-IC:\\gtkmm64\\lib\\sigc++-2.0\\include" "-IC:\\Program Files (x86)\\GnuWin32\\include" "-IC:\\Program Files (x86)\\GnuWin32\\include\\gsl" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\mrconvert.o" "..\\src\\mrconvert.cpp"

我认为其中一些应改为-L。例如

"-IC:\\Users\\Jesse\...lib"

应该是

-L"C:\\Users\\Jesse\...lib"

应该进入联系线。即连接所有内容的第二行。