C: Problems with preprocessing definition [closed] - c

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I see the following error when compiling...
./src/gettext.h:17:22: fatal error: libintl.h: No such file or directory
So I look at the code and see...
#ifndef NO_GETTEXT
# include <libintl.h>
#else
# ifdef gettext
# undef gettext
# endif
# define gettext(s) (s)
# ifdef ngettext
# undef ngettext
# endif
# define ngettext(s, p, n) ((n == 1) ? (s) : (p))
#endif
I add a file called config.h which I add the following....
#define NO_GETTEXT
But it doesn't seem to have defined it because I still see the error. I am rather new to C so I am not sure what is up. Any help?

Oops should be...
LOCAL_CFLAGS := -DNO_GETTEXT
in my MakeFile

Related

how to solve unterminated ifndef? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 months ago.
Improve this question
How can I solve the error: unterminated #ifndef when am trying to use header files with my defined functions in C ?
In file included from test.c:1:
main.h:1: error: unterminated #ifndef
1 | # ifndef _MAIN_H_
|
this is the code
# ifndef _MAIN_H_
# ifdef _MAIN_H_
int now(void);
# endif
~
I though #endif solves it all but failed.
The #ifdef should be a #define for you to have working #include guard. As originally written the #ifndef is missing the matching #endif.
Symbols that start with underscore followed by an uppercase letter are reserved (6.4.2.1). Use MAIN_H instead.
You could also use #pragma once which is a non-standard, but widely supported, alternative to the include guard.
Leave out the ~ of the code listing as it's vi's EOF marker and not part of your header file.

Linux open file dialog [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 months ago.
Improve this question
Im trying to program a open file dialog in C. I dont want to use any gui projects.
It seems there's XORG and wayland so I'm guessing I need to implement open file dialog for both of those.
So far my program looks like this
#ifdef _WIN32
OPENFILENAME ofd;
memset(&ofd,0,sizeof(ofd));
ofd.lStructSize = sizeof(ofd);
ofd.lpstrFile = filename;
ofd.nMaxFile = MAX_PATH;
ofd.Flags = OFN_FILEMUSTEXIST;
#endif
#ifdef __linux__
#endif

How can I read a line from a file and check if that row contains an #include for call an header file? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am trying to read all the content of a .c file and print out in another .o file all the source code of the first file, replacing all the #include <....> in this way:
Input: #include<string.h>
Ouput: "string.h"
I have to work in pure C, without the chance to use any C++ libraries
Can someone please help me with this issue?
A simple sed on your file maybe?
sed 's/.*#include *\(<|"\)\(.*\)\(>|"\).*/"\2"/' < input.c > output.o

How to pass argument from Makefile to a program? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I want to pass directory of Makefile to a function.
For example:
Makefile
$(DIR) = makefile directory
program
int main(int argc,char argv[])
char directory = argv[1]
How can I do that?
EDIT
Clarificaion. I want my app to work outside of the directory that i compiled it in.
Passing a symbol at compile time is done with the -D option
(example is C++ but you can transpose to C easily). You can either only define the symbol, or give it a value (which is what you want here).
DIR=$(shell pwd)
mytarget:
#echo "DIRECTORY=$(DIR)"
$(CXX) mysource.cpp -D"DIRECTORY=$(DIR)" -o mysource
Then, in your source file, the symbol DIRECTORY will hold the path. To check this, you need an additional trick (known as "double expansion"):
#define STR1(x) #x
#define STR(x) STR1(x)
#include <iostream>
int main()
{
std::cout << "directory is " << STR(DIRECTORY) << "\n";
}
You can check this similar question, and see here about the D flag.
In case the directory you need to pass is static (i.e. always the same) you can use the -D C compiler option:
cc -DDIRECTORY=/home/user/...
In your C source code you can then use DIRECTORY.

eclipse, c, auto increment build number define [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I'm using LPCXpresso (Eclipse) that is building C code for some MCU.
Is there some magic feature (plugin) that I can use to automatic increment a define?
#define BUILD_NUMBER 1252 // auto increment at each build
Few years ago I wrote some simple exec for doing that on older IDEs (pre build events) but there may be a simpler solution now.
Thank you in advance,
You can this to use to store your build number and create an header at a pre-build stage by makefile, eg:
#id=`cat .build_id`; id=$$[id+1]; printf "#define BUILD_NUMBER\t\t0x%08X\n" $$id >> $#; echo "$$id" > .build_id
You can also add date and time, eg:
#printf "#define BUILD_DATE\t\t0x%04X%02X%02X\n" `date +"%-Y %-m %-d"` >> $#;
#printf "#define BUILD_TIME\t\t0x%02X%02X%02X\n" `date +"%-H %-M %-S"` >> $#;

Resources