header-files

C++ pass variable from .cpp to header file

戏子无情 提交于 2019-12-11 19:31:27
问题 this relates to a question i asked previously: C++ array in header file in the main.cpp file there is a variable called fin1 ifstream fin1("ACW2_data.txt"); this might be a stupid question, but how can i use the value of this variable from main.cpp in the header file? (ie. is there a way to pass variables between the two files?) any other info about using header files may help Thanks in advance 回答1: This variable can be declared in the header file as an extern . extern ifstream fin1; Now you

Automake: How to use a header from one library in a another library in a sister directory

醉酒当歌 提交于 2019-12-11 19:28:18
问题 My directory set up: libone one.c one.h Makefile.am libtwo two.c #includes one.h two.h Makefile.am ... Makefile.am configure.ac ... Now when I do autoreconf -fvi and configure and make, I get the error from two.c: could not find one.h. How do I setup the include paths in Makefile.am's? Any help appreciated. 回答1: Either do it the quick'n'dirty way #include "../libone/one.h" or (preferred, because then it doesn't matter whether one.h is installed or in the source tree or split out into a

How to include the basic header files which are available with C in UNIX?

落花浮王杯 提交于 2019-12-11 18:06:08
问题 When we work on Turbo C, we get all the functions and header files by default which we can include normally by #inlcude eg: stdlib.h, math.h But when writing a simple program using such header files I am getting error because I'm unable to include these files. Aren't these header files available by default for us to use? If yes then how to use such header files? When I used a function sqrt in "math.h" I was getting error as math.h was not getting included so I had to include it in the

Undefined reference to cmph functions even after installing cpmh library

爷,独闯天下 提交于 2019-12-11 17:14:32
问题 I am using gcc 4.4.3 on ubuntu. I installed cmph library tools 0.9-1 using command sudo apt-get install libcmph-tools Now, when I tried to compile example program vector_adapter_ex1.c , gcc is able to detect cmph.h library in its include file but is showing multiple errors like vector_adapter_ex1.c:(.text+0x93): undefined reference to cmph_io_vector_adapter' vector_adapter_ex1.c:(.text+0xa3): undefined reference to cmph_config_new' vector_adapter_ex1.c:(.text+0xbb): undefined reference to

C++: Including header-file fails compilation but including source cpp file compiles

こ雲淡風輕ζ 提交于 2019-12-11 15:17:12
问题 This is probably really simple, but it's hindering me on my way down c++ road. I am currently reading through accelerated c++ and I decided to overkill one of the exercises. It all worked well and my code ran fine until I split it into a header and separate source file. When I import my .cpp source file containing some functions I wrote, everything runs fine. But when I try to import the functions through a header file it fails horribly and I get the following error. I am compiling with gcc

C++ redeclaration inconsistency/interestingness

♀尐吖头ヾ 提交于 2019-12-11 14:49:17
问题 I was answering this question when I thought of this example: #include <iostream> void func(int i); void func(); int main (){ func(); return 0; } void func(){} In the above example, the code compiles fine. However, in the below example, the code does not compile correctly: #include <iostream> void func(); int func(); int main (){ func(); return 0; } void func(){} This is the error that occurs when this code is compiled (in clang++): file.cpp:4:5: error: functions that differ only in their

Makefile - rebuild with modified header files

你。 提交于 2019-12-11 13:37:43
问题 In my project I have some header files which contain methods (e.g. for template classes). All these header files are included in a single file header.h , which is then included in every cpp file. This way, I have to change the code just in one place. There are also some .h files without a corresponding .cpp file. Then I have this makefile: # Makefile .PHONY: run clean rebuild CC = g++ CFLAGS = -Wall -Ofast -std=c++0x -pthread RM = rm -f EXEC = main SRC = $(wildcard *.cpp) OBJ = $(SRC:.cpp=.o)

Once-only pseudo-generic header in C

雨燕双飞 提交于 2019-12-11 13:30:06
问题 After some work on the generic vector I asked about on this question, I would like to know if there is any way of checking that each instanciation of the library is only done once per type. Here is what the current header file looks like: #ifndef VECTOR_GENERIC_MACROS #define VECTOR_GENERIC_MACROS #ifndef TOKENPASTE #define TOKENPASTE(a, b) a ## b #endif #define vector_t(T) TOKENPASTE(vector_t_, T) #define vector_at(T) TOKENPASTE(*vector_at_, T) #define vector_init(T) TOKENPASTE(vector_init_,

Can't include the JPEG_SUPPORT headers in a dlib cpp file

不问归期 提交于 2019-12-11 09:24:06
问题 I was trying to compile a cpp file: the face-finder in dlib: http://dlib.net/face_detection_ex.cpp.html. But when I ran it, it said I had to include the libraries for jpg and png files: processing image /home/james/Work/Coding/Sources/Image/950.jpg exception thrown! Unable to load image in file /home/dave/Code/Resources/Images/500.jpg. You must #define DLIB_JPEG_SUPPORT and link to libjpeg to read JPEG files. Do this by following the instructions at http://dlib.net/compile.html. Note that you

C++ file including C header file [duplicate]

房东的猫 提交于 2019-12-11 08:46:55
问题 This question already has answers here : error: 'INT32_MAX' was not declared in this scope (7 answers) Closed 5 years ago . I need to include a C header file in my C++ project but g++ throws "not declared in this scope" errors. I read that i need to use extern "C" keyword to fix it but it didn't seem to work for me. Here is a dummy example triggering this error. main.cpp: #include <iostream> extern "C" { #include "includedFile.h" } int main() { int a = 2; int b = 1212; std::cout<< "Hello