header-files

Placing header files in a subdirectory of /usr/include with automake?

本小妞迷上赌 提交于 2019-11-30 04:57:47
If I write a library, and have header files for development included, and have a src/Makefile.am like this: AM_CFLAGS = -std=c99 -Wall -Werror -Os lib_LTLIBRARIES = libmylibrary.la libmylibrary_la_SOURCES = a.c b.c include_HEADERS = a.h b.h Everything works nicely. However, a.h and b.h are installed directly under /usr/include (or /usr/local/include ). What should I do to get them installed, in a subdirectory specific to my library, e.g. /usr/include/mylibrary ? ptomato As well as pkginclude_HEADERS , which you mention, you can also install header files into an arbitrary subdirectory of /usr

default parameters in .h and .cpp files

做~自己de王妃 提交于 2019-11-30 04:20:41
COMPILER: g++ 4.7.2 Ok. So I am confused about default parameters in .h and .cpp files. It is mentioned in many places( including this site) that default parameters can be added only in .h files and not in .cpp files. However, this code proves it wrong: test1.h #pragma once #include <iostream> using namespace std; class Class{ public: Class(int, int, int=1); }; test1.cpp #include "test1.h" Class::Class(int a, int b=2, int c) { cout<<a<<" "<<b<<" "<<c<<endl; } int main() { Class a(1); return 0; } Now, according to what I have tested, default parameters can be added to .cpp files. However, the

Include .cpp instead of header(.h)

前提是你 提交于 2019-11-30 03:11:38
There are some cases when we include .cpp file instead of standard header file (.h), for example: #include "example.cpp" instead of #include "example.h" It seems to work but is this safe or should I avoid it? What about the compilation time? It's lazy coding. Use header files. Yes they can increase compile time but they mean that you can easily re-implement chunks of your code, or better yet, another developer could at anytime. The header file serves as a template for what your C/C++ code is going to do. It's a bad idea to discard or ignore it. I agree with Kerrek SB. I did this once. I was

#include <cmath> vs #include <math.h> in a C++ program [duplicate]

五迷三道 提交于 2019-11-30 02:41:52
问题 This question already has answers here : Should I include stddef.h or cstddef for size_t (5 answers) Should I include <xxxx.h> or <cxxxx> in C++ programs? (2 answers) Closed 6 years ago . What are the considerations for including the former rather than the latter in a C++ program? I always include math.h , stdlib.h and never cmath , cstdlib etc. I don't understand the reason the latter even exist, could someone please enlighten me? 回答1: Prefer to include the <c ...> headers. They are C++

What's the benefit for a C source file include its own header file

怎甘沉沦 提交于 2019-11-30 01:40:32
问题 I understand that if a source file need to reference functions from other file then it needs to include its header file, but I don't understand why the source file include its own header file. Content in header file is simply being copied and pasted into the source file as function declarations in per-processing time. For source file who include its own header file, such "declaration" doesn't seem necessary to me, in fact, project still compile and link no problem after remove the header from

How to have CMake show headers-that are not part of any binary target-in the IDE?

て烟熏妆下的殇ゞ 提交于 2019-11-30 01:24:50
In our workflow, we can have a module A that is composed of several header files, module A not producing any binary (side note: it will obviously be used by other modules, that include some of the headers from module A to produce binaries). A good example would be a header-only library, for which CMake 3 introduces a good support thanks to the notion of INTERFACE library (see this SO answer , and CMake's documentation of the feature ). We can make an interface library target out of module A : add_library(module_A INTERFACE) That gives us all the nice features of CMakes targets (it is possible

What mean file with extension “h.in”?

江枫思渺然 提交于 2019-11-29 23:54:24
I am studying the C language, and I saw a new extension that I had not seen before. What do files with the extension like library.h.in mean? Is it as the simple header with extension ".h"? What's the difference? These files are usually the input for autoconf which will generate final .h files. Here's an example from PCRE: #define PCRE_MAJOR @PCRE_MAJOR@ #define PCRE_MINOR @PCRE_MINOR@ #define PCRE_PRERELEASE @PCRE_PRERELEASE@ #define PCRE_DATE @PCRE_DATE@ Autoconf will replace all variables ( @…@ ) with the respective values and the result will be a .h file. Daniel Fischer Typically, a .h.in

Header files inclusion / Forward declaration

馋奶兔 提交于 2019-11-29 22:38:44
In my C++ project when do I have to use inclusion ( #include "myclass.h" ) of header files? And when do I have to use forward declaration of the class ( class CMyClass; )? As a rule try the forward declaration first. This will reduce compile times etc. If that doesn't compile go for the #include . You have to go for the #include if you need to do any of the following: Access a member or function of the class. Use pointer arithmetic. Use sizeof. Any RTTI information. new / delete , copy etc. Use it by value. Inherit from it. Have it as a member. Instance in a function. (6,7,8,9 from @Mooing

Code duplication between typedefs and explicit instantiations

房东的猫 提交于 2019-11-29 21:16:41
问题 tree.h template<typename Functor, char Operator> class binary_operation : public node { // ... unimportant details ... unsigned evaluate() const; void print(std::ostream& os) const; }; typedef binary_operation<std::plus<unsigned>, '+'> addition; typedef binary_operation<std::multiplies<unsigned>, '*'> multiplication; // ... tree.cpp template<typename Functor, char Operator> unsigned binary_operation<Functor, Operator>::evaluate() const { // ... unimportant details ... } template<typename

How to see the actual order of include files after preprocessing?

旧巷老猫 提交于 2019-11-29 19:44:45
问题 I have one .cpp file that includes a few header files. These header files may include other header files as well. Include guards are in place to prevent including the same file twice. Knowing that each file is only included once. Is there a way to figure out the eventual order in which all headers will be included? I tried gcc -E to get the preprocessor output, but the generated code doesn't seem usable for extracting the information that I want. Can anyone help? Edit The reason why I'm