FAQ Database Discussion Community


Using a header of headers instead of repeating

c,header-files
Is there any reason not to write one header file that #includes all other header files and just #include that one header in each c file? Each header file is setup #ifndef ... #define ... #endif To clarify the duplicates; I was asking about user written code not system headers...

C - redefinition error in Xcode

c,xcode,header-files,redefinition
My c header file has the following error message in Xcode Redefinition of 'entry' But it works perfectly when I compile it using gcc in command line. Could any of you give an explanation of why? This is snapshot.h: #ifndef SNAPSHOT_H #define SNAPSHOT_H #define MAX_KEY_LENGTH 16 #define MAX_LINE_LENGTH 1024 typedef...

Missing headers for kernel in bzImage loaded on qemu

linux-kernel,kernel,header-files,kernel-module,qemu
I am trying to compile a kernel module of kernel version 3.2.0 on a linux kernel bzImage loaded on a qemu emulator, however I am getting the following error: /lib/modules/3.2.0/build no such file or directory. I tried to look up solutions over the net but nothing specific related to solve...

Can I put an inline function on a header file in c++? [duplicate]

c++,inline,header-files
This question already has an answer here: c++ inline function? 6 answers I have a function which is very small and it is not part of any class. Can I put it in a header file to make it inline? some thing such as this: inline int add(int a,...

C++ Headers Missing from Visual Studio

c++,visual-studio-2013,header-files
I'm trying to start a new C++ project after a long time away from it. Visual Studio 2013 Express created the project successfully (a win32 console application), but it's not finding any of the typical headers, such as iostream.h and conio.h. #include <iostream.h> returns a not-found error. I searched the...

C++ include guards and multiple definition errors

c++,header-files,redefinition,include-guards
I have a situation where I need to include a header file (stack.h) in 2 .cpp files. The set up is as below: //------"stack.h"------// std::stack<int> s; int a; void doStackOps(); void print(); //------"stack.cpp"------// #include "stack.h" //------"main.cpp"------// #include "stack.h" Question 1 My header file contains 2 variables and 2 methods. I...

Implementing Nuance Speech Recognition on Swift, cannot listen to onResult, onError… events

ios,swift,delegates,speech-recognition,header-files
I have two parts of my Speech Recon project with Nuance, the .h file of a module (ObjectiveC) and aViewController (swift). I want to set up aSpeechRecognition object in my swiftviewController, and listen to onBegin, onStop... and such methods. The only way to make it compile is to use nil...

declaration/initialization issue with multiple files in C++

c++,compilation,linker,header-files
I know how to call a simple function (i.e. add(int x, int y){return x+y;} and nothing more) from a second .cpp file. Now I wanted to go one step further and get following problem: in my main.cpp I got one line like this (important part is the variable a_wt at...

XCode include system file instead of local file

c++,ios,xcode,compilation,header-files
I am working on an iOS project and include ifaddrs.h in one of my files using #include <ifaddrs.h> Recently, my code stopped working (in particular, getifaddrs) and I noticed that BLWebSocketsServer delivers a getifaddrs.h/.c which seems to cause issues. If I remove those two files from XCodes "Headers" and "Compile...

Clarification regarding assert.h header file in C

c,header-files
I am working with some open source code in C that uses the assert.h header file #include <assert.h> I think I know what assert is used for and why it is in the program, i.e. it is a macro used for debugging purposes which tests some condition and will possibly...

Once-only pseudo-generic header in C

c,templates,generics,header-files,c-preprocessor
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...

XCode does not find header file, but command click opens it

ios,objective-c,xcode,header-files
XCode gives me an error that cannot find header file, but command-clicking on the header opens the header file. The strange behaviour is that in another class of the same project the same header file is recognized. This header is inside a custom framework. I correctly import it with #import...

How should I declare global variables in my C++ project?

c++,c,include,global-variables,header-files
I have two matrices as global variables. However, when I run my project, I get a apache Mach-O linker error in xCode that says that my global variables are declared more than once. I've determined the problem to be the placement of my global variables and the imports of the...

Declaring variable in C header

c,arrays,header-files
I want to include a variable declared in an external file in C. My project structure looks like this. foo.h foo.c variable.c main.c What I'm doing right now is /* main.c */ #include "foo.h" #include <stdio.h> #include <stdlib.h> int main() { bar(); printf("%d\n", a); return 0; } /* foo.h */...

Is it OK to Edit GCC Header Files?

c++,gcc,header-files
I was trying to compile some example code from MSDN with GCC on Windows 7 (please ignore the use of goto and the terrible formatting; it's not my code): #include <stdio.h> #include <windows.h> typedef struct _TOKEN_ELEVATION { DWORD TokenIsElevated; } TOKEN_ELEVATION, *PTOKEN_ELEVATION; BOOL IsProcessElevated() { BOOL fIsElevated = FALSE; DWORD...

SDL won't display image in window when called from class

c++,image,class,header-files,sdl-2
I'm trying to organize my code a bit more, so I tried putting the SDL2 code used for displaying windows/images into a class. The window opens, the code runs successfully, and the image seems to be loading fine, -but the image will not appear when the code is arranged in...

How would I write a header and implementation file for FizzBuzz in Objective-C?

objective-c,header-files,main,fizzbuzz
EDIT TO ADD: SOLVED AT BOTTOM, see main.m I wanted to try the FizzBuzz Challenge in Objective-C since I'm teaching myself the language. I easily coded it in main.m, but I wondered if there was a way to code it via a header and implementation file. For my main.m version,...

Why can a user change from private to public?

c++,linux,header-files
I've made a programm with libraries. One library has a interface for to include a header for an extern programm call: class IDA{ private: class IDA_A; IDA_A *p_IDA_A; public: IDA(); ~IDA(); void A_Function(const char *A_String); }; Then I opened the header with Kate and placed class IDA_A; IDA_A *p_IDA_A; into...

Including header files into static library

c,gcc,static-libraries,header-files,static-linking
Since every time when we link against a static library we also need to include the header files, I am wondering if it is possible to archive into the static library, when creating it, those heads? Say I have two object files foo1.o and foo2.o generated by gcc foo1.c -I...

C++ - need advice on how to properly design a multi-file program

c++,design,header-files
Ok, so basically I need to create a simple game using Allegro 5 and C++. I want to split it into separate modules so it's easier to manage. My question is: what is the proper way to manage "moving" between different files? Specifically, I'd like to have a file called...

Why do both “std::printf” and “printf” compile when using rather than in C++?

c++,namespaces,header-files
To my knowledge, headers of the form cxyz are identical to xyz.h with the only difference being that cxyz places all of the contents of xyz.h under the namespace std. Why is it that the following programs both compile on GCC 4.9 and clang 6.0? #include <cstdio> int main() {...

When using inheritance is it necessary to “#include” the header file of child's parent class. C++

c++,header-files,multiple-inheritance
I'm working on a multiple inheritance project in C++. I have separate files for class definitions (.h) and implementations (.cpp). Since this is the first time I've used inheritance in C++ (the rest of our assignments have been in C#) somethings are a little unclear. Do I need to #include...

C++ Declaration of class variables in header or .cpp?

c++,header-files,variable-declaration
So far, I've been using classes the following way: GameEngine.h declares the class as follows class GameEngine { public: // Declaration of constructor and public methods private: InputManager inputManager; int a, b, c; // Declaration of private methods }; My GameEngine.cpp files then just implement the methods #include "____.h" GameEngine::GameEngine()...

problems solving "undefined reference to [costum class]

c++,header-files,undefined-reference
i've been struggling with an error for about a day now and still haven't found a way to fix my error, specifically an undefined reference error: undefined reference to `Lines2D::Point2D::~Point2D()' engine.cc /Graphicsengine line 20 C/C++ Problem I get this error for every object of my "Lines2D.h" class i call upon,...

Can I declare a variable as const in the public header and not in the private header?

c,linker,const,header-files
For example, can I do something like this so that only foo.c can modify the variable foo?: foo.h: extern const int foo; void foo_init(void); void foo_reinit(void); foo.private.h: int foo; void foo_init(void); void foo_reinit(void); foo.c: #include "foo.private.h" void foo_init() { foo = 1; /* ... */ } void foo_reinit() { foo++;...

C++ header/implementation file and overloaded operators

c++,operator-overloading,header-files
It's not often that I work in C++ and I've run into a simple error that is holding me up. In Xcode I have the following two errors: In Event.h: Control reaches end of non-void function In Event.cpp: Overloaded operator must have at least one argument of class or enumeration...

BluetoothAPIs.h syntax error

c++,bluetooth,header-files
I have following problem. When I try to include BluetoothAPIs.h, the compiler shows me many syntax errors, example: [C++ Error] BluetoothAPIs.h(133): E2141 Declaration syntax error [C++ Error] BluetoothAPIs.h(171): E2238 Multiple declaration for '__checkReturn' ... This is BluetoothAPIs.h "invalid" part of code: 132-138 __checkReturn HBLUETOOTH_RADIO_FIND WINAPI BluetoothFindFirstRadio( __in const BLUETOOTH_FIND_RADIO_PARAMS *...

Definition of Include file

c++,c,include,header-files
I have seen a separation of header files in two Visual Studio folders,Include Files and Header files, where headers with public API have been in Include Files folder and others in Header files folder. Is the term "include file" used and recognized this way? What I have seen is just...

SDL UpdateWindowSurface() returns -1 if called from a class (in separate file)

c++,class,window,header-files,sdl-2
Today I started a C++/SDL2 Snake clone, and I've been looking for ways to make my code neater, -particularly with classes. I tried to put all the SDL code used for the window/display in a class. When I run the code, the window closes instantly. From the error tests I...

Undeclared identifier error C2065 of definitions, that are clearly there

c++,visual-studio-2012,header-files
I am working with multiple projects, where I use header files of one project inside the other. Now I added a project to the C/C++ Additional Include Directories, but after that I get this error with declarations that are all in the resource.h file. My guess is that because both...

error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include “stdafx.h”' to your source?

c++,visual-studio,visual-studio-2013,header-files,stdafx.h
I have a project, originally developed on Microsoft Visual C++ . NET, Version 7.0.9466 and it works very well. I tried to use MS 2013 to run my project, and when I try to build the project, I have this error menssage: error C1010: unexpected end of file while looking...

Built-in Function Confusion [closed]

c++,c,function,header-files
There are two types of function in C and C++. Built-in functions and user defined functions. To use the built-in function we need to include the header file in the in which that particular function prototype is present say for using pow() function we include math.h. My question if the...

Qt compiler cannot find the header file

c++,qt,header-files
I know it's a quite common issue but I haven't found a comprehensive answer on the following question. I have Qt 5.4.1 MSVC2013 build running on Windows 8.1. Here is a look on my project files: And here is what my .pro file looks like: QT += core gui greaterThan(QT_MAJOR_VERSION,...

C file extension if you include C file inside another

c,header-files
I have a C file with all static functions, related to one and same sub-task. Some of the functions are quite long - 20-30 lines. I want to include it in another C file. What must be the file extension (in order things to considered professional). Shall I do it...

how to use standard c header files in arduino

c,arduino,header-files
I have a simple C library that looks like this: //mycLib.h #ifndef _MY_C_LIB_h #define _MY_C_LIB_h typedef struct {char data1; int data2; } sampleStruct; extern void mycLibInit(int importantParam); extern void mycLibDoStuff(char anotherParam); extern void sampleStruct mycLibGetStuff(); #endif //mycLib.c sampleStruct _sample; void mycLibInit(int importantParam) { //init stuff! //lets say _sample.data2 = importantParam...

No such module, swift, xcode 6.2

ios,xcode,swift,header-files
Here is a screenshot: .h module, as you can see, copied in project, but Xcode ignore it. I'd try uninstall XCode and install 6.2 (beta 5), In Terminal, I tried rm -rf ~/Library/Developer/Xcode/DerivedData , defaults delete com.apple.dt.Xcode... but it didn't help....

C: Why do we include header files, which declare but don't define?

c,include,header-files
At a high level, I understand we use #include statements to make code from other files available to the current file. But I don't understand why we include a header file, which contains declarations but no definitions. Maybe I need to learn more about the compilation/linking process to fully understand...

When to use static inline instead of regular functions

c,static,inline,header-files
When I inspect other people's codes, I sometimes encounter static inline functions implemented in header files as opposed to regular function implementations in C files. For example, cache.h header file (https://github.com/git/git/blob/master/cache.h) of git contains many such functions. One of them is copied below; static inline void copy_cache_entry(struct cache_entry *dst, const...

How to make “common headers” for a library work when it's installed in /usr/include?

c,static-libraries,header-files
I'm working on packaging a library which has a bunch of header files, and a .a static library. The C headers for the library are all in the root folder of the library, but the headers use some external typedefs held in a common/ directory. I tried copying all the...

Where is the -I (captial i) path relative to in g++?

c++,include,g++,preprocessor,header-files
I am in the App folder of my project. I run the following command to compile character.cpp g++ -Wall -std=c++11 -I../App -c Character/character.cpp -o Obj/character.o which is in App/Character directory. character.cpp has the following include #include "Inventory/inventory.hpp" where the folder of inventory.cpp is App/Inventory. I thought because I am running...

How am I able to use read() and write() without including “unistd.h”?

c,file-io,header-files,syscall,unistd.h
I have used syscalls read() and write() in my program WITHOUT including "unistd.h" header file in the program. But still the program works and gives expected results. After running the program, i thought i will read the man page for read() and write(). In the man 2 page for read()...

Trying to create Library in C++. Test project can't find implementation of declared constructor?

c++,constructor,static-libraries,header-files
I'm learning C++, but hit a plateau trying to create a library. Using Visual Studio 2013, I get this error: Error 1 error LNK2019: unresolved external symbol "public: __thiscall Polynomial::Polynomial(void)" ([email protected]@[email protected]) referenced in function _main A:\Medier\Desktop\PolyLib\Test\Test.obj Test The testproject is currently cut down to this: #include "A:\Medier\Desktop\PolyLib\PolyLib\PolyLib.h" using namespace std;...

What are good tools which can help to get rid of C/C++ header files? [closed]

c++,c,c++11,header-files
Languages like Java or C# do not require header files and do just fine with placing everything in a single source file. So it is obvious that the concept of header files serves little to no purpose and is merely a historical artefact of C/C++ which causes unnecessary complexity and...

How to share same header files between kernel modules and userspace applications.

linux-kernel,macros,linux-device-driver,header-files,ioctl
I want to implement a simple module in which an ioctl() method is used. In the kernel module, I use kernel macros, such as _IO(), _IOWR(), etc., to define my own ioctl sub-commands. In facts, I don't care the actual values of these definitions for that I will always use...

gcc -I doesn't change the include directory

c++,gcc,header-files
I have a folder called code/, under this folder I have a folder called include/ and the source file called code.cc, the include/ contains the header files a.h, b.h, and these two header files also exist somewhere else, in order to use the header files in the include/ folder, I...

What does an underscore “_” mean in Swift?

swift,module,naming-conventions,header-files,naming
I just found this while browsing through the Swift module headers: protocol _ObjectiveCBridgeable { Similarly: protocol _SequenceType { Coming from an Objective-C background, this seems highly unconventional to me. The underscore _ usually implies that the concerned entity is private, and is often hidden in terms of header visibility. Why...

Missing header files from an shared C++ project

c++,visual-studio,header-files
I have downloaded an .NET solution, which is contains 2 C# and 1 C++ project. When I build the solution, the Error List says: Error 1 error C1083: Cannot open include file: 'libavformat/avformat.h': No such file or directory C:\Users\Dinh\Downloads\TestOnvif-master\TestOnvif-master\FFmpegRTSPCppCLR\FFmpegMedia.cpp 19 1 TestFFmpegLib Actually, I see an folder in solution directory...