3

私はLinux開発にまったく慣れておらず、メインの別のファイルのクラスを使用するのに問題があります。(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 に答える