我认为,我可能不正确地将cmake设置为错误,(或为此不正确地设置了cmake),或者我对C ++或同时对这两者感到不满和生锈,甚至更多。我只想添加一个标头并将单独的代码添加到为opengl加载图像的类中。我还将它们放在与Linux文件树中其他库并行的另一个目录中。
主项目文件夹中包含main cmakelists.text文件,该文件称为“ maficengine”。内部还有一个“ build”文件,一个“ common”文件和“ external”文件以及一个名为“ Mafic”,“ maficGuiSourceFiles”的文件和一个名为“ distrib”的文件。我认为我们可以只专注于2.“ mafic”和“ external”。在mafic中,我有一个名为mafic.cpp的文件,它具有我的主要功能,并且是入口点。在外部文件中,还有一个名为“ myCustomHeaders”的文件夹。其中包含一个名为“ loadTexture.cpp”的文件,其中包含loadTexture类的声明和定义。同样在“ myCustomHeaders”内部,有一个“包含”文件,其中包含“ loadTexture.h”……我似乎无法实例化LoadTexture lt的实例;并调用loadtexture()函数;我希望它在mafic.cpp中的第187行
#cmakelists.text file from main project folder
# CMake entry point
cmake_minimum_required (VERSION 3.0)
project (maficengine )
find_package(OpenGL REQUIRED)
add_library(loaders
external/myCustomHeaders/loadTexture.cpp
external/myCustomHeaders/include/loadTexture.h
)
set(SOURCES external/myCustomHeaders/loadTexture.cpp )
# Compile external dependencies
add_subdirectory (external)
# On Visual 2005 and above, this module can set the debug working directory
cmake_policy(SET CMP0026 OLD)
cmake_policy(SET CMP0079 NEW)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/external/rpavlik-cmake-modules-fe2273")
include(CreateLaunchers)
include(MSVCMultipleProcessCompile) # /MP
if(INCLUDE_DISTRIB)
add_subdirectory(distrib)
endif(INCLUDE_DISTRIB)
include_directories(
external/AntTweakBar-1.16/include/
external/glfw-3.1.2/include/
external/glm-0.9.7.1/
external/glew-1.13.0/include/
external/assimp-3.0.1270/include/
external/bullet-2.81-rev2613/src/
external/myCustomHeaders/include
common/
)
set(ALL_LIBS
${OPENGL_LIBRARY}
glfw
GLEW_1130
loaders
)
add_definitions(
-DTW_STATIC
-DTW_NO_LIB_PRAGMA
-DTW_NO_DIRECT3D
-DGLEW_STATIC
-D_CRT_SECURE_NO_WARNINGS
)
# Tutorial 17
add_executable(mageengine
Mafic/mafic.cpp
common/shader.cpp
common/shader.hpp
common/controls.cpp
common/controls.hpp
common/texture.cpp
common/texture.hpp
common/objloader.cpp
common/objloader.hpp
common/vboindexer.cpp
common/vboindexer.hpp
common/quaternion_utils.cpp
common/quaternion_utils.hpp
#Mafic/loadTexture.h
#Mafic/loadTexture.cpp
Mafic/StandardShading.vertexshader
Mafic/StandardShading.fragmentshader
)
target_link_libraries(mageengine
${ALL_LIBS}
ANTTWEAKBAR_116_OGLCORE_GLFW
loaders
)
这是mafic.cpp
#include <loadTexture.h>
int main( void )
{
loadTexture lt;
lt.loadtexture();
}
这是我的loadTexture.cpp
class loadTexture
{
public:
loadTexture();
~loadTexture();
void loadtexture(){
fprintf(stdout, "loadtexture does something, that's a positive result for this test");
}
};
最后是我的loadTexture.h
[code]
#pragma once
#include <GL/glew.h>
//GLuint image;
void loadtexture();
[/code]
希望它不会出错,但我得到...
aaron@Zog:~/Desktop/maficengine/build$ make
[ 2%] Built target ANTTWEAKBAR_116_OGLCORE_GLFW
[ 2%] Built target GLEW_1130
[ 2%] Built target loaders
[ 6%] Built target glfw
[ 7%] Building CXX object CMakeFiles/mageengine.dir/Mafic/mafic.cpp.o
/home/aaron/Desktop/maficengine/Mafic/mafic.cpp:1:9: warning: #pragma once in main file
#pragma once
^~~~
/home/aaron/Desktop/maficengine/Mafic/mafic.cpp: In function ‘int main()’:
/home/aaron/Desktop/maficengine/Mafic/mafic.cpp:187:1: error: ‘loadTexture’ was not declared in this scope
loadTexture lt;
^~~~~~~~~~~
/home/aaron/Desktop/maficengine/Mafic/mafic.cpp:187:1: note: suggested alternative: ‘loadtexture’
loadTexture lt;
^~~~~~~~~~~
loadtexture
/home/aaron/Desktop/maficengine/Mafic/mafic.cpp:189:2: error: ‘lt’ was not declared in this scope
lt.loadtexture();
^~
CMakeFiles/mageengine.dir/build.make:62: recipe for target 'CMakeFiles/mageengine.dir/Mafic/mafic.cpp.o' failed
make[2]: *** [CMakeFiles/mageengine.dir/Mafic/mafic.cpp.o] Error 1
CMakeFiles/Makefile2:75: recipe for target 'CMakeFiles/mageengine.dir/all' failed
make[1]: *** [CMakeFiles/mageengine.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2
aaron@Zog:~/Desktop/maficengine/build$