How to make g++ search for header files in a specific directory?

A/code.cpp #include <B/file.hpp> A/a/code2.cpp #include <B/file.hpp> Compile using: g++ -I /your/source/root /your/source/root/A/code.cpp g++ -I /your/source/root /your/source/root/A/a/code2.cpp Edit: You can use environment variables to change the path g++ looks for header files. From man page: Some additional environments variables affect the behavior of the preprocessor. CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH OBJC_INCLUDE_PATH Each variable’s value is a list of … Read more

How can I create C header files [closed]

Open your favorite text editor Create a new file named whatever.h Put your function prototypes in it DONE. Example whatever.h #ifndef WHATEVER_H_INCLUDED #define WHATEVER_H_INCLUDED int f(int a); #endif Note: include guards (preprocessor commands) added thanks to luke. They avoid including the same header file twice in the same compilation. Another possibility (also mentioned on the … Read more

How to read a CMake Variable in C++ source code

The easiest way to do this, is to pass the LIBINTERFACE_VERSION as a definition with add_definition: add_definitions( -DVERSION_LIBINTERFACE=${LIBINTERFACE_VERSION} ) However, you can also create a “header-file template” and use configure_file. This way, CMake will replace your @LIBINTERFACE_VERSION@. This is also a little more extensible because you can easily add extra defines or variables here… E.g. … Read more

Can I write C++ code without headers (repetitive function declarations)?

Use Lzz. It takes a single file and automatically creates a .h and .cpp for you with all the declarations/definitions in the right place. Lzz is really very powerful, and handles 99% of full C++ syntax, including templates, specializations etc etc etc. Update 150120: Newer C++ ’11/14 syntax can only be used within Lzz function … Read more

How to use the tool include-what-you-use together with CMake to detect unused headers?

CMake 3.3 introduced the new target property CXX_INCLUDE_WHAT_YOU_USE that can be set to the path of the program include-what-you-use. For instance this CMakeLists.txt cmake_minimum_required(VERSION 3.3 FATAL_ERROR) add_executable(hello main.cc) find_program(iwyu_path NAMES include-what-you-use iwyu REQUIRED) # If using CGAL<3.18, you remove REQUIRED and use # if(NOT iwyu_path) # message(FATAL_ERROR “Could not find the program include-what-you-use”) # endif() … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)