3

我对 linux 开发很陌生,并且在我的 main.js 文件中使用来自单独文件的类时遇到了麻烦。我在制作时遇到的错误(在使用cmake创建makefile之后)是系统没有命名类型,我认为系统类中的代码是正确的,就好像我编译时没有尝试创建系统类的对象我没有错误,所以我认为这可能与我编写 CMakeLists.txt 文件的方式有关。

这是我的 CMakeLists 文件:

    cmake_minimum_required (VERSION 2.6)
    project (GL_PROJECT)

    add_library(system system.cpp)

    include_directories(${GL_PROJECT_SOURCE_DIR})
    link_directories(${GL_PROJECT_BINARY_DIR})

      find_package(X11)

      if(NOT X11_FOUND)
        message(FATAL_ERROR "Failed to find X11")
      endif(NOT X11_FOUND)

       find_package(OpenGL)
      if(NOT OPENGL_FOUND)
        message(FATAL_ERROR "Failed to find opengl")
      endif(NOT OPENGL_FOUND)

    set(CORELIBS ${OPENGL_LIBRARY} ${X11_LIBRARY})

    add_executable(mainEx main.cpp system.cpp)

    target_link_libraries(mainEx ${CORELIBS} system)

我在源目录中有我的 main.cpp、system.h(类定义)和 system.cpp(类实现)

主要:

      #include"system.h"


      system sys;

      int main(int argc, char *argv[]) {

      while(1) 
        {
            sys.Run();
        }

      }

X11 和 GL 包括等在 system.h 中,我认为其中的代码是正确的并且不会导致错误(因为如果我不尝试创建类的实例,它会构建得很好)。为简洁起见,我省略了实际的标头和实现,希望这将是 CMakeList 文件中的一个明显错误,但如有必要,我也可以添加这些吗?

有任何想法吗?

提前致谢。

编辑:这是终端中的错误

    [tims@localhost build]$ make
    Scanning dependencies of target system
    [ 33%] Building CXX object CMakeFiles/system.dir/system.cpp.o
    Linking CXX static library libsystem.a
    [ 33%] Built target system
    Scanning dependencies of target mainEx
    [ 66%] Building CXX object CMakeFiles/mainEx.dir/main.cpp.o
    /home/tims/Code/GL_Project/main.cpp:5:1: error: ‘system’ does not name a type
    /home/tims/Code/GL_Project/main.cpp: In function ‘int main(int, char**)’:
    /home/tims/Code/GL_Project/main.cpp:11:3: error: ‘sys’ was not declared in this scope
    make[2]: *** [CMakeFiles/mainEx.dir/main.cpp.o] Error 1
    make[1]: *** [CMakeFiles/mainEx.dir/all] Error 2
    make: *** [all] Error 2

编辑2:system.h

    #include<stdio.h>
    #include<stdlib.h>
    #include<X11/X.h>
    #include<X11/Xlib.h>
    #include <GL/gl.h>           
    #include <GL/glx.h>                                                                
    #include <GL/glu.h>    

    class system {
    public:
        system(void);

        ~system(void);

        void CreateGLXWindow();

        void Run();

        //Contains information about X server we will be communicating with 
        Display *display;

    XEvent xEvent;

    //Window instance
    Window rootWindow;
    XVisualInfo *xVisInfo;
    XSetWindowAttributes setWindAttrs;
    XWindowAttributes xWindAttrs;

    //GL 
    GLXContext context;
    Colormap  cmap;

    Window window;
private:

};
4

1 回答 1

6

类名与在中声明的函数system冲突,该函数包含在您的. 您要么需要重命名类,要么将其移动到命名空间中,因为在 C++ 中类和函数不能具有相同的名称。int system(const char*)stdlib.hsystem.hsystem

于 2012-05-31T16:07:21.650 回答