When I build my program, I have next error:
Error C1083
Cannot open include file: 'ZZ.h': No such file or directory NTL
C:\Progs\NTL\src.cpp
My code:
#include <ZZ.h>
int main(){
ZZ a, b, c;
return 0;
}
Download library ntl 11.5.1 for Windows from https://libntl.org/download.html
Build static library
File \ New \ Project Existing Code...
Next
Project file location: C:\2\WinNTL-11_5_1\src
Preject name: ntl
Next
Project type: Static library (LIB) project
Finish
Project \ Properties \ VC++ Directories \ Include Directories \ Edit: C:\2\WinNTL-11_5_1\include
Build \ Rebuild Solution
Copy static library _NTL.lib in my project NTL
In NTL project:
Project \ Properties \ VC++ Directories \ Library Directories -> ./NTL
Project \ Properties \ Linker \ Input \ Additional Dependencies -> _NTL.lib
All of the NTL header files are in a directory called NTL. You need to reflect this in your #include directive.
#include <NTL/ZZ.h>
Related
Minimal example .zip
I'm trying to use SoLoud in my Qt project.
I managed to successfully compile & use it with this cmake file:
file(GLOB_RECURSE AUDIOSOURCE ${CMAKE_CURRENT_LIST_DIR}/SoLoud/src/audiosource/*.c*)
file(GLOB_RECURSE CORE ${CMAKE_CURRENT_LIST_DIR}/SoLoud/src/core/*.c*)
file(GLOB_RECURSE FILTER ${CMAKE_CURRENT_LIST_DIR}/SoLoud/src/filter/*.c*)
add_compile_definitions(WITH_MINIAUDIO)
set(SOLOUD_SRCS
SoLoud/src/backend/miniaudio/soloud_miniaudio.cpp
${CMAKE_CURRENT_LIST_DIR}/SoLoud/src/c_api/soloud_c.cpp
${AUDIOSOURCE}
${CORE}
${FILTER}
)
add_executable(output main.cpp ${SOLOUD_SRCS})
target_include_directories(output PUBLIC ${CMAKE_CURRENT_LIST_DIR}/SoLoud/include)
My main project is built with Qmake. So I'm trying to translate it...
INCLUDEPATH += SoLoud/include
DEFINES += "WITH_MINIAUDIO=\"\""
SOURCES += SoLoud/src/backend/miniaudio/soloud_miniaudio.cpp \
SoLoud/src/c_api/soloud_c.cpp \
$$files("SoLoud/src/audiosource/*.c*", true) \
$$files("SoLoud/src/core/*.c*", true) \
$$files("SoLoud/src/filter/*.c*", true)
HEADERS += $$files("SoLoud/include/*.h", true) \
This produces a wall of errors:
https://pastebin.com/pUQuysEr
Why?
BTW: i'm aware that recursive search of *.c* files is bad practice. However, that's what library's authors recommend and I gave up trying to find every single .cpp i need (there were MANY).
I'm attempting to build a CMakeLists.txt for my project. It needs to include SDL, OpenGL, and GLEW as well as all of my *.cpp and *.h files in different directories. All files used to build the project are in the Project Source Directory that cmake is called in.
The error:
In file included from /home/me/repos/AlchemyEngine/alchemy/alcEngine.cpp:1:0:
/home/me/repos/AlchemyEngine/alchemy/alcEngine.h:69:18: fatal error: glew.h: No such file or directory
#include <glew.h>
I think it'd be easiest to show the steps for setting this project up in Visual Studio (which works as I used to develop from there) and hope I can get help recreating the setup in my CMakeLists.txt file.
Setting up the project in Visual Studio
1. Includes
Project -> *ProjectName* Properties -> VC++ Directories
Click Include Directories -> Click down-arrow- > edit
Browse for the include files (...\SDL2-OpenGL-GLEW-VC++\include)
2. Libraries
Project -> *ProjectName* Properties -> VC++ Directories
Click Library Directories -> Click down-arrow -> edit
Browse for the library files (...\SDL2-OpenGL-GLEW-VC++\lib)
3. Linkers
Project -> *ProjectName* Properties -> Linker -> Input
Click Additional Dependencies -> Click down arrow -> edit
Copy into box:
SDL2.lib
SDL2main.lib
SDL2_image.lib
OpenGL32.lib
glu32.lib
glew32.lib
4. DLLs
Build project with chosen entry point to create Debug folder with executable.
Copy the .dll files from the ...\SDL-OpenGL-GLEW-VC++\dropInExe folder and paste into the
Debug folder with the project executable
(...\*Project Folder*\Debug)
Here is my CMakeLists.txt file as it stands
cmake_minimum_required (VERSION 3.5)
project (AlchemyEngine)
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
include_directories (
alchemy/
alchemy/event/
alchemy/scene/
alchemy/resource/
alchemy/render/
alchemy/util/
game/
#SDL2_OpenGL_GLEW_VC++/include
)
set( srcs
alchemy/alcEngine.cpp
alchemy/event/alcEvent.cpp
alchemy/render/alcRenderer.cpp
alchemy/render/alcSprite.cpp
alchemy/resource/alcResource.cpp
alchemy/resource/alcShader.cpp
alchemy/resource/alcTexture.cpp
alchemy/scene/alcObject.cpp
alchemy/scene/alcScene.cpp
alchemy/util/alcBlockAllocator.cpp
alchemy/util/alcStackAllocator.cpp
game/Player.cpp
Main.cpp
)
add_library (libraries STATIC SDL2_OpenGL_GLEW_VC++/include/)
add_executable (alc ${PROJECT_SOURCE_DIR}/${srcs})
target_link_libraries(alc libraries)
set_target_properties(libraries PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(alc PROPERTIES LINKER_LANGUAGE CXX)
After configuration and generation, $CMAKE_SOURCE_DIR/build/bin contains:
liblibraries.a
glew32.dll
libpng16-16.dll
SDL2.dll
SDL2_image.dll
zlib1.dll
It seems to me that my method for including the header files is incorrect, but poking around the CMake documentation and other stack exchange posts hasn't produced any better results. I have a feeling it has to do with the linker step, but I cannot figure out how to specify the dependencies in CMake.
I can tree and post the output too if the project structure is that important for this issue.
FINAL EDIT:
The error was fixed in the answer below, here is my final CMakeLists.txt for anyone interested
# Outputs executable(s) in {PROJECT_SOURCE_DIR}/build/bin/
# specify min version and project name
cmake_minimum_required (VERSION 3.5)
project (AlchemyEngine)
# set output paths for binaries/executable
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
# include project header files
include_directories (
alchemy/
alchemy/event/
alchemy/scene/
alchemy/resource/
alchemy/render/
alchemy/util/
game/
)
# create source files definition
set( srcs
alchemy/alcEngine.cpp
alchemy/event/alcEvent.cpp
alchemy/render/alcRenderer.cpp
alchemy/render/alcSprite.cpp
alchemy/resource/alcResource.cpp
alchemy/resource/alcShader.cpp
alchemy/resource/alcTexture.cpp
alchemy/scene/alcObject.cpp
alchemy/scene/alcScene.cpp
alchemy/util/alcBlockAllocator.cpp
alchemy/util/alcStackAllocator.cpp
game/Player.cpp
Main.cpp
)
# add a library target to be built from the source files
add_library (libraries STATIC SDL2_OpenGL_GLEW_VC++/lib/)
# specify include directories
target_include_directories(libraries PUBLIC SDL2_OpenGL_GLEW_VC++/include/)
# specify libraries to use when linking the library
target_link_libraries (libraries
${PROJECT_SOURCE_DIR}/SDL2_OpenGL_GLEW_VC++/lib/glew32.lib
${PROJECT_SOURCE_DIR}/SDL2_OpenGL_GLEW_VC++/lib/glew32s.lib
${PROJECT_SOURCE_DIR}/SDL2_OpenGL_GLEW_VC++/lib/SDL2_image.lib
${PROJECT_SOURCE_DIR}/SDL2_OpenGL_GLEW_VC++/lib/SDL2.lib
${PROJECT_SOURCE_DIR}/SDL2_OpenGL_GLEW_VC++/lib/SDL2main.lib
)
# create the executable using the source files defined above
add_executable (alc ${PROJECT_SOURCE_DIR}/${srcs})
# specify the headers
target_include_directories(alc PUBLIC ${PROJECT_SOURCE_DIR})
# link the library to the project
target_link_libraries(alc libraries)
# force the linker language because there's some c stuff in the library files
set_target_properties(libraries PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(alc PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(libraries PRIVATE SDL2_OpenGL_GLEW_VC++/include/) should be using PUBLIC so that this path is known to any executable target that links against libraries such as target_link_libraries(alc libraries).
This is assuming that glew.h resides in the SDL2_OpenGL_GLEW_VC++/include/ directory.
Since target_include_directories is using a relative path (I'm pretty sure it is relative to the source tree) you need to make sure that this is correct for your directory tree.
How to add all files in some sub-directory in qt project file.
for example, my source tree is:
src
app/
foo/
ui/
common/
Now I add all files like this
SOURCES += ./*.cpp \
./app/*.cpp \
./app/foo/*.cpp \
./ui/*.cpp \
./common/*.cpp
Is there any way to add all these files under src directory to SOURCES?
You have to use the files function:
SOURCES += $$files("*.cpp", true)
I'm using Qt Creator 2.7.0 on ubuntu 13.04.
I've just recently ran into the idea of using libraries, and they're a whole new thing for me.
I've just figured that I need to have the following in my application's .pro file to use a library of my own:
LIBS += -L<lib's dir> -l<lib's name>
INCLUDEPATH += <headers' dir>
// for example:
LIBS += -L$$PWD/../MyLib/release/ -lMyLib
INCLUDEPATH += $$PWD/../MyLib/src/
As you see, I have all my projects in a folder called Programming (the .. in this case)
Each of my project have .pro and .pro.user files in the root, source files in a sub folder /src and the release in an other sub folder /release.
So, this is what my Programming folder looks like:
Programming
MyLib
MyLib.pro
MyLib.pro.user
src
myclass.h
myclass.cpp
release
libMyLib.a
Makefile
myclass.o
MyApp
MyApp.pro
MyApp.pro.user
src
main.cpp
release
main.o
Makefile
MyApp
However, I figured that I could create a folder Programming/libs/, and add libMyLib.a and myclass.h files inside that libs folder.
I would do the same for all of my libraries, and then I could always include them like this:
LIBS += -L$$PWD/../lib/ -lMyLib
INCLUDEPATH += $$PWD/../lib/
The problem is, I'd get include path for every library stored on my computer and the libs folder would become a mess, especially if there are two headers with same name on different libraries.
I'm really new to using libraries, is there a general solution on how they should be located on your computer, and how to include them into your projects?
You could mimic libraries like Boost and have a directory tree like this:
MyLib
build
Makefile, .pro or .sln file here
lib
MyLib
// your .so / .a here
include
MyLib
// your .h here
src
// your .cpp here
CMake or qmake file here
This way you have an out-of-source build tree (in build/) so that your binary files are not mixed up with your source files.
The lib/ and include/ directories are handy because you can then define an install build target. If you then type
make install
it will copy everything to usr/local/lib and user/local/include so that your App can simply do #include <MyLib/some_header.h> and you can link directly against your library binaries (because you copied everything to a location in your system wide path). There is also no danger of name clashes because you wrapped it inside your own MyLib subdirectory.
I need to convert Qt Project to CMake , as i want to integrate it with other projects which are already in CMake .
The Qt .Pro file is as follows ,
TEMPLATE = app
INCLUDEPATH += ./lib
# Input
HEADERS += dollar/GestureTemplate.h \
dollar/PathWriter.h \
dollar/GeometricRecognizerTypes.h \
dollar/GeometricRecognizer.h \
dollar/SampleGestures.h \
lib/GestureTemplate.h \
lib/PathWriter.h \
lib/GeometricRecognizerTypes.h \
lib/GeometricRecognizer.h \
lib/SampleGestures.h \
lib/MultiStrokeGestureTemplate .h \
lib/MultiStrokeGestureTemplate .h \
lib/MultiStrokeGestureTemplate .h \
lib/MultiStrokeGestureTemplate .h \
lib/SampleMultiStrokeGestures.h \
lib/MultipleStrokeGestureTemplate.h \
lib/utils.h
SOURCES += main.cpp \
lib/GeometricRecognizer.cpp
LIBS += -L/usr/lib \
-lml \
There is only one directory Lib and in the main path there is main.cpp , all the other files are inside Lib directory .
I don't know much about cmake i have come up with the following cmake list for the above qt project.
cmake_minimum_required (VERSION 2.6)
Project(dollar)
INCLUDE_DIRECTORIES("lib")
# Make Executable
ADD_EXECUTABLE(main main.cpp)
# Link the executable to the Hello library.
TARGET_LINK_LIBRARIES(main -lml -L/usr/lib)
cmake succeeds but after that make gives me many errors ,see the error log -> http://www.text-upload.com/read,4022366863337 .What all additions i require to make in CMake List ?.
It seems that you have missed lib/GeometricRecognizer.cpp file
# Make Executable
ADD_EXECUTABLE(main main.cpp lib/GeometricRecognizer.cpp)