I'm just getting my feet wet in C with some work in GStreamer, but seem to already be stuck.
I'm compiling the project in X Code using GNU99. The <time.h> header file that is part of the GStreamer code has no reference to time_t, which is used by some of the files.
Therefore I'm seeing:
/Library/Frameworks/GStreamer.framework/Versions/1.0/Headers/glib/gbookmarkfile.h:171:11:
Unknown type name 'time_t'; did you mean 'size_t'?
Do some C versions have varying header files for <time.h> that have done away with the time_t type? If so, is there a workaround?
Edit:
Looks like it has something to do with how XCode is searching for the <time.h> header file.
It should grab it from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/time.h, but it's instead using one from FFmpeg
Under header search paths, I see this:
/Library/Frameworks/GStreamer.framework/Versions/1.0/Headers
This setting is directly from the tutorial download
My workaround solution was to add
#include </Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/time.h>
to the FFMPEG time.h file.
Your path to the proper time header file may vary.
Related
I'm having an incredibally hard time finding answers to this for Windows. As if the majority of people use Linux...
Anyways, I need a custom CSV parsing library for C. I found one and downloaded the header file. I tried adding #include <csvparser.h> at the top of my c program but of course, it says file not found. I placed the downloaded file in the same directory as the program.
I think i need to be able to specify an absolute path in the include or place the file csvparser.h in the include directory, but I know how to do neither of these things. What is the default include directory in Windows? I use gcc as my compiler. How can i specify an absolute path in the include statement, on windows? i can find no answer to this.
Thanks!
EDIT
Thank you for the quick reply, I seem to have included the file correctly, but now I'mhaving problems using it.
I found the program at https://sourceforge.net/p/cccsvparser/wiki/Home/
I placed it in the source directory and tried using it, bbut when I try the usage example I'm getting an error. This is my code:
#include <stdio.h>
#include <string.h>
#include "csvparser.h"
#define MAXCHAR 10000
int main() {
// int i = 0;
// file, delimiter, first_line_is_header?
CsvParser *csvparser = CsvParser_new("../MagicProg/Files/MagicProg_csv_ikoria.csv", "|", 1);
return 0;
}
When I try executing this, geany gives me the error:
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Geoff\AppData\Local\Temp\ccsiwJPq.o:hello.c:(.text+0x22): undefined reference to `CsvParser_new'
What am I doing wrong? thanks again
If you're including something that's in your source directory you need to use a different style:
#include "csvparser.h"
The angle-brackets form is exclusively for things found in your include path, not in your source directory. That's reserved for things like OS and compiler headers, as well as system-installed libraries.
I made the huge newb error of not including the src files along with the header file. I blame myself. thanks everyone for help
I'm trying to include a folder that contains a combination of around 60 .h and .hpp files. This folder contains libraries for programming robots with a Wallaby (a mini-computer-like device) for Botball competition. include is located in the same place as main.c (inside code). Up until now, this is what my header for including libraries looks like:
#include "../code/include/accel.h"
Just like accel.h, I have 60 other .h and .hpp files inside include. So, coming to my question, do I need to type out all the 60 header lines? or is there a way to include the include folder.
I'm using Clion for this project, if I can't include the folder itself, does anyone know of a shortcut in Clion to include all the files in include.
I was also thinking of using some sort of placeholder for the folder name and only specify the file type. So, for example: #include "../code/include/(generic placeholder name).h". I have no clue if something like this exists.
I would also request you to keep in mind that I'm a beginner to programming, so please keep your answers simple.
This is just for some extra info:
The Wallaby is a mini computer to which you would connect your sensors, motors, servos and cameras in order to control a robot for the Botball competition. Usually, one can connect to the Wallaby either via Wifi Direct or a cable and write programs on it directly through an online interface (not entirely sure of the word for it, but you just type in an IP address in your browser and it brings up an interface where you can make projects and code). All the code written in that interface saves directly onto the Wallaby. Here the default include statement is #include <kipr/botball.h>, so I'm assuming that botball.h (which is located on the Wallaby's storage) has all those 60 libraries consolidated in it. I got the include folder that I'm using from GitHub. This link was provided to me by one of the Botball organisers. So the main point in me trying to download the library is so that I can write and successfully compile code even when I'm not connected to the Wallaby. Hope this provides some relevant context.
Thank you for your answers!
What I'd do is
Create (maybe with scripting tools or a specific program) a "all.h" file which includes all the other header files
#ifndef ALL_INCLUDED
#define ALL_INCLUDED
#include "accel.h"
#include "bccel.h"
//...
#include "zccel.h"
#endif
Include "all.h" in your main file
#include "../code/include/all.h"
You can create "all.h" automatically every time you build your code.
CLion is an IDE for Clang and GCC. These compilers are instructed to search paths for include files by specifying -I<path> command line arguments. Any number may be specified, and they are searched in the order given, and the first match found is the file that gets included.
I am not familiar with CLion specifically but no doubt it has a dialog somewhere where you can set header file search paths.
Edit: It seems that CLion may not make this so straightforward. I understand that you have to add then via CMake: https://cmake.org/cmake/help/v3.0/command/include_directories.html#command:include_directories, but after that, the IDE will not recognise the header in the editor and will warn you of unrecognised files and will not provide code comprehension features. I believe it will build nonetheless.
I have a some code files and a directory with some header files in sub-directories, structured like this:
code\my_file.c
code2\other_file.c
headers
where headers contains the sub-directories openssl, curl.
When I use #include <openssl/evp.h> inside my_file.c it fails with:
fatal error: openssl/evp.h: No such file or directory
However, it works from other_file.c
Additionally, when I include the full path #include "../headers/openssl/evp.h it works fine.
Is there a reason one file in my project knows to find the openssl dir and the other doesn't?
Using Eclipse
I tried changing properties, by adding an include path:
but it didn't work...
This what fixed it for me but if someone has another answer, I'd love to hear it
So, it turns out I just needed to do the exact same thing in the GNU C++ tab also:
My understanding was always that by doing #include <header.h> it looks in the system include directories, and that #include "header.h" it looks in the local directory. But I was just looking at the python source code and it uses the "header.h" method to define headers in a sibling directory.
So in py3k/Python/ast.c it does #include "Python.h". But Python.h is in py3k/Include/Python.h
Is this something common that I've just never seen, not having worked on any real large C project? How do I tell, at least my IDE, to look in py3k/Include?
Update
I figured out how to tell my IDE to include them, it was just me being stupid and a spelling error. But I'm more interested in why "" works. Is that not the different between "" and <>?
Both #include <header> and #include "header" look in "implementation-defined places", i.e. it depends on the compiler you are using and its settings. For #include <h> it's usually some standard system include directories and whatever you configure the compiler to look in additionally.
The difference between the two versions is that if the search for #include "header" is not supported or fails, it will be reprocessed "as if it read #include <header>" (C99, ยง6.10.2).
You need to somehow tell your compiler what directories to search in -- for GCC this means using the -I flag. Look it up for your combination of IDE / compiler.
I'm trying to add an header file to dev-C++ but when I compile it it doesn't work.
Here are my exact steps (for my example, I'm trying to get mysql.h to work):
copy "mysql.h" into c:\dev-c++\includes
check that in dev-C++ tools > compiler options > directories > c includes and c++ includes have the path to "c:\dev-c++\includes"
include #include at the top of my file
compiled
This is what the dev-C++ compiler told me:
13 C:\Documents and Settings\Steve\Desktop\server code\setup1\main.c `mysql' undeclared (first use in this function)
As well as other errors due to not locating the header file
Are the steps I've outlined correct? Or is there something else I need to do to get the header files to compile.
P.S. I tried doing the same with VS2008 (put mysql.h in the vs2008 include folder, etc)
but still have the same error. I would like to stick with Dev-c++ if possible.
You didn't say how you included it at the top of your file. This should work if you did
#include "mysql.h"
rather than
#include <mysql>
which is a mistake that people sometimes make.
EDIT: Perhaps try using relative paths rather than an absolute path (as you seem to be doing) when specifying additional include directories? I don't know if that would make a difference (and I don't have the time to check) but I've always used relative paths and it's always worked for me (it's also good practice anyway). So, instead of
C:\Projects\ProjectName\Include
something like
\Include or ..\Include depending on your project file structure.
Dev-C++ is a port of GCC, so try this page: http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html.
Note that you probably have to tinkle with the Makefile.
I had the same problem....
You need to put the #include after "using namespace std;", in order to use your header file in the standard namespace.
For me it is working.
Best wishes.
On the left side, right click the Project and choose "Add to Project", and then select the header file.
Its very simple ...
Just make Your header file and save it as .h extension.
Then use #include "file_name.h" instead of using include
Example-
This is my header file.
#include<iostream>
using namespace std;
namespace Ritesh
{
int a;
int b;
void sum();
}
void Ritesh::sum()
{
cout<<a+b;
}
Then use of it-
#include<iostream>
#include "Ritesh.h"
using namespace std;
using namespace Ritesh;
int main()
{
a=4;b=6;
sum();
}
Output-
Output of program