【问题标题】:C++: Including libraries, multiple definitions (ARPACK++)C++:包括库、多个定义(ARPACK++)
【发布时间】:2014-08-13 20:04:27
【问题描述】:


我目前正在尝试使用 ARPACK++ 等其他 C++ 库,但在 ARPACK++ 的包含文件夹中遇到了多个定义问题。
这是我的编译行,其中包括我需要的几个库:

 g++ -g -Dlinux -I/home/LapEVSol/arpack++/include -I/usr/local/include/g++-3 -o main main.cc Basis.cc IntegrationRule.cc Matrix.cc Mesh.cc PDE.cc /home/LapEVSol/arpack++/libsuperlu_4.3.a  /home/LapEVSol/arpack++/libarpack.a /home/LapEVSol/arpack++/liblapack.a /home/LapEVSol/arpack++/librefblas.a /home/LapEVSol/arpack++/libgfortran.a  -lm

编译器将这个错误交给我:

Matrix.cc: In member function ‘ARluSymMatrix<double>* CSCMatrix::CreateARluSymMatrix()’:
Matrix.cc:338:25: warning: address of local variable ‘MatrixName’ returned [-Wreturn-local-addr]
ARluSymMatrix<double> MatrixName(rows, nnz, entries, rowIndex, colPointer, 'L');
                     ^
/tmp/ccb6n5wo.o: In function `void std::_Destroy_aux<true>::__destroy<int*>(int*, int*)':
/home/LapEVSol/arpack++/include/arerror.h:163: multiple definition of `ArpackError::Set(ArpackError::ErrorCode, std::string const&)'
/tmp/ccR5YW3o.o:/home/LapEVSol/arpack++/include/arerror.h:163: first defined here
/tmp/ccb6n5wo.o: In function `void std::_Destroy_aux<true>::__destroy<int*>(int*, int*)':
/home/LapEVSol/arpack++/include/arerror.h:163: multiple definition of `ArpackError::code'
/tmp/ccR5YW3o.o:/home/LapEVSol/arpack++/include/arerror.h:163: first defined here
/tmp/ccpDlwxP.o: In function `__gnu_cxx::new_allocator<Mesh::Node>::new_allocator()':
/home/LapEVSol/arpack++/include/arerror.h:163: multiple definition of `ArpackError::Set(ArpackError::ErrorCode, std::string const&)'
/tmp/ccR5YW3o.o:/home/LapEVSol/arpack++/include/arerror.h:163: first defined here
/tmp/ccpDlwxP.o: In function `__gnu_cxx::new_allocator<Mesh::Node>::new_allocator()':
/home/LapEVSol/arpack++/include/arerror.h:163: multiple definition of `ArpackError::code'
/tmp/ccR5YW3o.o:/home/LapEVSol/arpack++/include/arerror.h:163: first defined here
collect2: error: ld returned 1 exit status
make: *** [all] Error 1

这有点奇怪,因为包含头文件“arerrorh.h”被包裹在一个正确的:

 #ifndef ARERROR_H
 #define ARERROR_H
 ...
 #endif

可能是我在链接或编译部分做错了吗?因为这几乎是我最不自信的部分。如果有人能告诉我我在这里做错了什么,我会很高兴。
提前致谢!

【问题讨论】:

  • 我现在更担心warning: address of local variable ‘MatrixName’ returned。是的,多重定义是在链接时,所以守卫定义不会帮助你

标签: c++ static-libraries arpack


【解决方案1】:

标头arerror.h 中有错误。将inline 放入ArpackError::Set 函数的定义中。另外,,修复 CSCMatrix::CreateARluSymMatrix 方法,它返回一个局部变量的地址。

【讨论】:

  • 我修复了那个部分。现在错误有点短,但仍然存在:/tmp/ccOcpFbY.o: In function __gnu_cxx::new_allocator&lt;Mesh::Node&gt;::new_allocator()': /home/LapEVSol/arpack++/include/arrseig.h:33: multiple definition of ArpackError::code'
  • @Log7 你修复了哪一部分?我建议了 2 个修复,一个用于错误,一个用于警告
  • @Log7 ArpackError::code 定义应该在 .cpp 文件中,而不是在标题中。为它制作一个 .cpp 文件并将其放入其中。
猜你喜欢
  • 2016-11-05
  • 2018-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-15
相关资源
最近更新 更多