abstract declarator'const <anonymous class =“”>'用作声明C ++

时间:2016-10-21 03:08:07

标签: c++

当我在我的ubuntu 14.04lts中编译一个名为ROPTLIB(http://www.math.fsu.edu/ROPTLIB/)的开源时,我遇到了一个问题。我写了一个CMakeLists.txt来自己编译代码。但我无法使用错误日志成功编译它,如下所示:

Scanning dependencies of target TestSimpleExample
[  1%] Building CXX object CMakeFiles/TestSimpleExample.dir/test/TestSimpleExample.cpp.o
In file included from /home/xxx/Documents/software/ROPTLIB_2016-04-29_CPP/Others/ForDebug.h:12:0,
                 from /home/xxxg/Documents/software/ROPTLIB_2016-04-29_CPP/test/TestSimpleExample.cpp:11:
/home/xxx/Documents/software/ROPTLIB_2016-04-29_CPP/Others/def.h:140:2: error: expected ‘;’ after class definition
/home/xxx/Documents/software/ROPTLIB_2016-04-29_CPP/Others/def.h:126:14: error: an anonymous struct cannot have function members
/home/xxx/Documents/software/ROPTLIB_2016-04-29_CPP/Others/def.h:140:2: error: abstract declarator ‘const<anonymous class>’ used as declaration
/home/xxx/Documents/software/ROPTLIB_2016-04-29_CPP/Others/def.h:140:4: error: expected unqualified-id before ‘nullptr’
In file included from /home/xxx/Documents/software/ROPTLIB_2016-04-29_CPP/test/TestSimpleExample.cpp:15:0:
/home/xxx/Documents/software/ROPTLIB_2016-04-29_CPP/Others/randgen.h:69:13: warning: ‘void next_state()’ declared ‘static’ but never defined [-Wunused-function]
/home/xxx/Documents/software/ROPTLIB_2016-04-29_CPP/Others/randgen.h:64:22: warning: ‘randgen::state’ defined but not used [-Wunused-variable]
/home/xxx/Documents/software/ROPTLIB_2016-04-29_CPP/Others/randgen.h:65:12: warning: ‘randgen::left’ defined but not used [-Wunused-variable]
/home/xxx/Documents/software/ROPTLIB_2016-04-29_CPP/Others/randgen.h:66:12: warning: ‘randgen::initf’ defined but not used [-Wunused-variable]
/home/xxx/Documents/software/ROPTLIB_2016-04-29_CPP/Others/randgen.h:67:23: warning: ‘randgen::next’ defined but not used [-Wunused-variable]
make[2]: *** [CMakeFiles/TestSimpleExample.dir/test/TestSimpleExample.cpp.o] Error 1
make[1]: *** [CMakeFiles/TestSimpleExample.dir/all] Error 2
make: *** [all] Error 2

然而,当我评论

//const class {
//public:
//  template<class T> // convertible to any type
//  operator T*(void) const // of null non-member
//  {
//      return 0;
//  } // pointer...
//  template<class C, class T> // or any type of null
//  operator T C::*(void) const // member pointer...
//  {
//      return 0;
//  }
//private:
//  void operator&(void) const; // whose address can't be taken
//} nullptr = {};

它可以成功编译,但它会得到错误的答案。我尝试在谷歌和其他论坛中搜索问题,但没有人可以帮助我。 这是我的CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.3)
  3 SET(ProjectName TestSimpleExample)
  5 PROJECT(${ProjectName})
  6
  7 FILE(GLOB_RECURSE all_files
  8         "${CMAKE_CURRENT_SOURCE_DIR}/Solvers/*.cpp"
  9         "${CMAKE_CURRENT_SOURCE_DIR}/Problems/*.cpp"
 10         "${CMAKE_CURRENT_SOURCE_DIR}/Others/*.cpp"
 11         "${CMAKE_CURRENT_SOURCE_DIR}/Manifolds/*.cpp"
 12     )
 13
 14 INCLUDE_DIRECTORIES(
 15         "${CMAKE_CURRENT_SOURCE_DIR}/Manifolds/"
 16         "${CMAKE_CURRENT_SOURCE_DIR}/Manifolds/Stiefel/"
 17         "${CMAKE_CURRENT_SOURCE_DIR}/Manifolds/CpxNStQOrth/"
 18         "${CMAKE_CURRENT_SOURCE_DIR}/Manifolds/EucPositive/"
 19         "${CMAKE_CURRENT_SOURCE_DIR}/Manifolds/Euclidean/"
 20         "${CMAKE_CURRENT_SOURCE_DIR}/Manifolds/Grassmann/"
 21         "${CMAKE_CURRENT_SOURCE_DIR}/Manifolds/L2Sphere/"
 22         "${CMAKE_CURRENT_SOURCE_DIR}/Manifolds/LowRank/"
 23         "${CMAKE_CURRENT_SOURCE_DIR}/Manifolds/Oblique/"
 24         "${CMAKE_CURRENT_SOURCE_DIR}/Manifolds/OrthGroup/"
 25         "${CMAKE_CURRENT_SOURCE_DIR}/Manifolds/PreShapeCurves/"
 26         "${CMAKE_CURRENT_SOURCE_DIR}/Manifolds/SPDManifold/"
 27         "${CMAKE_CURRENT_SOURCE_DIR}/Manifolds/SPDTensor/"
 28         "${CMAKE_CURRENT_SOURCE_DIR}/Manifolds/Sphere/"
 29         "${CMAKE_CURRENT_SOURCE_DIR}/Problems/"
 30         "${CMAKE_CURRENT_SOURCE_DIR}/Problems/ElasticCurvesRO/"
 31         "${CMAKE_CURRENT_SOURCE_DIR}/Problems/EucFrechetMean/"
 32         "${CMAKE_CURRENT_SOURCE_DIR}/Problems/EucPosSpCd/"
 33         "${CMAKE_CURRENT_SOURCE_DIR}/Problems/EucQuadratic/"
 34         "${CMAKE_CURRENT_SOURCE_DIR}/Problems/GrassRQ/"
 35         "${CMAKE_CURRENT_SOURCE_DIR}/Problems/ObliqueTestSparsePCA/"
 36         "${CMAKE_CURRENT_SOURCE_DIR}/Problems/PreShapePathStraighten/"
 37         "${CMAKE_CURRENT_SOURCE_DIR}/Problems/SPDMean/"
 38         "${CMAKE_CURRENT_SOURCE_DIR}/Problems/SPDTensorDL/"
 39         "${CMAKE_CURRENT_SOURCE_DIR}/Problems/SphereConvexHull/"
 40         "${CMAKE_CURRENT_SOURCE_DIR}/Problems/StieBrockett/"
 41         "${CMAKE_CURRENT_SOURCE_DIR}/Problems/StieSoftICA/"
 42         "${CMAKE_CURRENT_SOURCE_DIR}/Problems/StieSparseBrockett/"
 43         "${CMAKE_CURRENT_SOURCE_DIR}/Problems/StieSumBrockett/"
 44         "${CMAKE_CURRENT_SOURCE_DIR}/Problems/WeightedLowrank/"
 45         "${CMAKE_CURRENT_SOURCE_DIR}/Solvers/"
 46         "${CMAKE_CURRENT_SOURCE_DIR}/Others/"
 47         "${CMAKE_CURRENT_SOURCE_DIR}/blas/"
 48         "${CMAKE_CURRENT_SOURCE_DIR}/lapack/"
 49     )
 54 message(STATUS "add include_directories " ${INCLUDE_DIRECTORIES})
 55 if(${CMAKE_COMPILER_IS_GNUCC})
 56     message (STATUS "add c++11 flags")
 58     add_definitions(-Wall -s -std=c++11 -g)
 59 endif()
 60
 61 set(LIB "${CMAKE_CURRENT_SOURCE_DIR}/lib${LIB}")
 62 message (STATUS "blas and lapack lib is in ${LIB}")
 63 #link_directories({${LIB}})
 64 #link_directories("${OpenBlas_LIB}/lib")

${CMAKE_CURRENT_SOURCE_DIR}/test/TestProductExample.cpp ${all_files})
     71 add_executable(${ProjectName} ${CMAKE_CURRENT_SOURCE_DIR}/test/TestSimpleExample.cpp ${all_files})
${CMAKE_CURRENT_SOURCE_DIR}/test/TestStieBrockett.cpp ${all_files})
 73 message(STATUS "complie src.o successfully")
 78 target_link_libraries(${ProjectName} lapack blas)
 79
 80 message (STATUS "CMAKE_C_COMPILER is ${CMAKE_C_COMPILER}, CMAKE_CXX_COMPILER is ${CMAKE_CXX_COMPILER}")
 81 message (STATUS "CMAKE_COMPILER_IS_GNUCC is ${CMAKE_COMPILER_IS_GNUCC}")

和我的make,gcc和g ++版本:

make -v:
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-pc-linux-gnu

gcc --version:
gcc (Ubuntu/Linaro 4.7.3-12ubuntu1) 4.7.3
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

g++ --version:   
g++ (Ubuntu/Linaro 4.7.3-12ubuntu1) 4.7.3
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

/home/xxxx/Documents/software/ROPTLIB_2016-04-29_CPP/Others/def.h:

    /*
This is the global head file. Every file in ROPTLIB will include this file.

---- WH
*/

#ifndef DEF_H
#define DEF_H

//#define MATLAB_MEX_FILE//For debug---

/*
If all the test files are included in a project, then only uncomment one of them to specify which test problem is run.
*/

//#define TESTEUCFRECHETMEAN
//#define TESTEUCQUADRATIC
//#define TESTPRODUCT
//#define TESTSPHERERAYQUO
//#define TESTSTIEBROCKETT
//#define TESTSTIESPARSEBROCKETT
//#define TESTGRASSRQ
//#define TESTCSO
//#define TESTSTIESOFTICA
//#define TESTTESTSPARSEPCA
//#define TESTWEIGHTEDLOWRANK
//#define TESTELASTICCURVESRO
//#define TESTMYMATRIX
//#define TESTSPDMEAN
//#define TESTPRESHAPEPATHSTRAIGHTEN
//#define TESTSPDTENSORDL
//#define TESTEUCPOSSPCD

#define TESTSIMPLEEXAMPLE
//#define TESTPRODUCTEXAMPLE

#include <cmath>
/*If ROPTLIB is not compiled in Matlab, then the following wrapper functions of blas and lapack
are included.*/
#ifndef MATLAB_MEX_FILE
    // blas and lapack related

    #include <dgemm.h>
    #include <dgetrf.h>
    #include <dgetrs.h>
    #include <dgemv.h>
    #include <dcopy.h>
    #include <ddot.h>
    #include <dscal.h>
    #include <daxpy.h>
    #include <dger.h>
    #include <dgeqp3.h>
    #include <dorgqr.h>
    #include <dormqr.h>
    #include <dtrsm.h>
    #include <dlarfx.h>
    #include <ddot.h>
    #include <dgesdd.h>
    #include <dgesvd.h>
    #include <dsymv.h>
    #include <dgetri.h>
    #include <dlapmt.h>
    #include <dgees.h>
    #include <dnrm2.h>
    #include <dgesv.h>
    #include <dsyevx.h>
    #include <dlamch.h>
    #include <dpotrf.h>
    #include <dtrtrs.h>
    #include <dsyevd.h>
    #include <dsyevr.h>
    #include <dsyev.h>

    #include <zdotc.h>
    #include <zgegs.h>
    #include <ztgsyl.h>
    #include <zgees.h>
    #include <ztrtrs.h>
    #include <zgemm.h>
    #include <zscal.h>
    #include <zgeqp3.h>
    #include <zunmqr.h>
    #include <zpotrs.h>
    #include <zgetrs.h>
    #include <zpotrf.h>
#endif // end of ifndef MATLAB_MEX_FILE

#ifdef _WIN64 // The following code is compiled only when this library is compiled in Windows (64-bit only)
    /*If the code is compile under DEBUG mode, then test wheter there is memory leakage or not*/
    #ifdef _DEBUG
    #define DEBUG_CLIENTBLOCK   new( _CLIENT_BLOCK, __FILE__, __LINE__)
    /*Use my code to help checking memory leakage. One has to define a global variable:
        std::map<integer *, integer> *CheckMemoryDeleted;
    before running the code.
    */
    //#define CHECKMEMORYDELETED
    #else
    #define DEBUG_CLIENTBLOCK
    #endif

/*This is used for checking the memory leakage in windows system*/
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>

/*This is used for checking the memory leakage in windows system if the code is run in DEBUG mode*/
#ifdef _DEBUG
#define new DEBUG_CLIENTBLOCK
#endif

#elif _WIN32 // The following code is compiled only when this library is compiled in Windows (both 32-bit and 64-bit only)
   //define something for Windows (32-bit and 64-bit, this part is common)
#elif __APPLE__ // The following code is compiled only when this library is compiled in MAC
    #include "TargetConditionals.h"
    #if TARGET_IPHONE_SIMULATOR
         // iOS Simulator
    #elif TARGET_OS_IPHONE
        // iOS device
    #elif TARGET_OS_MAC
        // Other kinds of Mac OS
    #else
        // Unsupported platform
    #endif
#elif __linux// The following code is compiled only when this library is compiled in Linux system
    // linux
    #ifdef __GNUC__
    const class {
    public:
        template<class T> // convertible to any type
        operator T*(void) const // of null non-member
        {
            return 0;
        } // pointer...
        template<class C, class T> // or any type of null
        operator T C::*(void) const // member pointer...
        {
            return 0;
        }
    private:
        void operator&(void) const; // whose address can't be taken
    } nullptr = {};
    #endif // end of __GNUC__
#elif __unix // all unices not caught above
    // Unix
#elif __posix
    // POSIX
#endif // end of checking platforms

/*If ROPTLIB is compiled in Matlab, then removing the underscore to make the wrappers consistant.*/
#ifdef MATLAB_MEX_FILE
    #include "mex.h"
    #include "blas.h"
    #include "lapack.h"
    #define integer ptrdiff_t
#define dgemm_ dgemm
#define dgetrf_ dgetrf
#define dgetrs_ dgetrs
#define dgemv_ dgemv
#define dcopy_ dcopy
#define ddot_ ddot
#define dscal_ dscal
#define daxpy_ daxpy
#define dger_ dger
#define dgeqp3_ dgeqp3
#define dorgqr_ dorgqr
#define dormqr_ dormqr
#define dtrsm_ dtrsm
#define dlarfx_ dlarfx
#define dgesdd_ dgesdd
#define dgesvd_ dgesvd
#define dsymv_ dsymv
#define dgetri_ dgetri
#define dgees_ dgees
#define dnrm2_ dnrm2
#define dgesv_ dgesv
#define dsyevx_ dsyevx
#define dlamch_ dlamch
#define dpotrf_ dpotrf
#define dtrtrs_ dtrtrs
#define dsyevd_ dsyevd
#define dsyevr_ dsyevr
#define dsyev_ dsyev

#define zdotc_ zdotc
#define zgegs_ zgegs
#define ztgsyl_ ztgsyl
#define zgees_ zgees
#define ztrtrs_ ztrtrs
#define zgemm_ zgemm
#define zscal_ zscal
#define zgeqp3_ zgeqp3
#define zunmqr_ zunmqr
#define zpotrs_ zpotrs
#define zgetrs_ zgetrs
#define zpotrf_ zpotrf
#endif // end of ifdef MATLAB_MEX_FILE

/*Help to debug the code*/
#include "ForDebug.h"

/*For obtaining the lower bound, upper bound of numbers of double precision*/
#include <climits>
#undef max
#undef min
#include <limits>
/*For obtain the computational time*/
#include "Timer.h"

#include <map>
#include <string>

typedef std::map<std::string, double> PARAMSMAP;

/*Define the number PI*/
#define PI 3.14159265358979323846264

#endif // end of DEF_H

1 个答案:

答案 0 :(得分:0)

def findDuplicate(l): n = len(l) - 1 # Get n as length of list - 1 return sum(l) - (n * (n + 1) / 2) # n*(n+1)/2 is the sum of integers from 1 to n 现在是关键字。尝试使用非保留标识符命名变量。