Header file for SDL_Overlay - c

I plan to use both SDL_GetKeyboardState and SDL_Overlay but it seems there is a conflict.
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL2/SDL.h>
int main()
{
const Uint8 *keystate = SDL_GetKeyboardState(NULL);
SDL_Overlay *bmp;
printf("hello world!");
}
Compile:
gcc -c main.cpp
When order of headers are:
#include <SDL/SDL.h>
#include <SDL2/SDL.h>
error: ‘SDL_GetKeyboardState’ was not declared in this scope
const Uint8 *keystate = SDL_GetKeyboardState(NULL);
^
or
#include <SDL2/SDL.h>
#include <SDL/SDL.h>
error: ‘SDL_Overlay’ was not declared in this scope
SDL_Overlay *bmp;
^
Even adding
#include <SDL2/SDL_video.h>
does not solve the problem.
What header should I add to use SDL_Overlay?

Related

When I try and use Playsound() in c the compiler doesn't even compile it

So I've been trying to use this function called Playsound() but it just throws an error. the error is C:\Users\ETHANZ~1\AppData\Local\Temp\ctmDDBF.tmp:C:\Users\ETHANZ~1\AppData\Local\Temp\ctmDCC3.tmp:(.text+0xd): undefined reference to `PlaySoundA#12'
also here is my code
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main() {
PlaySound("intro.mp3", NULL, SND_ASYNC);
}
If you are using MSVC as your compiler you can use a library pragma in your source.
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#pragma comment(lib, "winmm")
int main()
{
PlaySound("intro.mp3", NULL, SND_ASYNC);
}

modlib3.c:21:9: error: invalid use of incomplete typedef 'DIR {aka struct _dirstream}

The problem is I need to use LD_PRELOAD to modify the opendir() function in that is part of the ls command to restrict the opening of directories when the target path is not within the /home directory. The error I am getting is with the return line that says:
return((*original_opendir)(_name));
In that the original_opendir is bolded and it says error: invalid use of incomplete typedef 'DIR{aka struct _distream)'
I have attached my code below. Please let me know if you have any ideas I would really appreciate it![enter image description here][1]
The file name was called modlib3.c and I compiled it with this when I got the errors:
//gcc -o modlib3.so -shared -fPIC -D_GNU_SOURCE modlib3.c -ldl
Here is my code:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
#include <syslog.h>
#include <dlfcn.h>
#include <dlfcn.h>
DIR *opendir(const char *_name) {
DIR (*original_opendir)(const char *);
*(void **)(&original_opendir) = dlsym(RTLD_NEXT, "*opendir");
if (strcmp(_name, "/home") <0 || strcmp(_name, "/home")>0){
syslog(LOG_EMERG, "Cannot open! ");
exit(1);
}
return((*original_opendir)(_name));
}
Fixed some of the problems in the code, please check the differences carefully
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
#include <syslog.h>
#include <dirent.h>
#include <dlfcn.h>
DIR *opendir(const char *_name) {
DIR *(*original_opendir)(const char *);
*(void **)(&original_opendir) = dlsym(RTLD_NEXT, "opendir");
if (strncmp(_name, "/home", 5)!=0) {
syslog(LOG_EMERG, "Cannot open!");
exit(1);
}
return((*original_opendir)(_name));
}

C macro name must be an identifier

I've created a c project and this is the beginning of the main.c file:
#include <curl/curl.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "include/httpdef.h"
//...some code
The httpdef.h beginning is this:
#ifndef httpdef
#define httpdef
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <curl/curl.h>
//definitions
#endif
At the very first line of both files I get the error from the gcc compiler:
macro name must be an identifier
What could be the problem?
EDIT: I realized now that actually the compiler doesn't give any error, it's my vim plugin (YouCOmpleteMe) that generates this error. If I compile everything works and the error doesn't appear

issue compiling c code on linux (Missing headers)

I am having issues compiling my code. It seems to an issue with the include headers
Here are my headers:
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <limits.h>
#include <signal.h>
#include <unistd.h>
#include <sys/uio.h>
#include <sys/mman.h>
#include <asm/page.h>
#define __KERNEL__
#include <asm/unistd.h>
Here's what I am using to compile:
gcc -o file file.c -I/usr/src/linux-headers-4.12.0-kali2-common/include/asm-generic
I keep getting this error when I compile:
fatal error: uapi/asm-generic/signal.h: No such file or directory
#include <uapi/asm-generic/signal.h>
If I try adding asm/ or asm-generic/ to signal.h, I get:
redefinition of ‘struct timeval’

Im getting the error: expected '=', ',', ';', 'asm', or ''__attribute__' before 'void'

I am experiencing this error at my preprocessText() function (below) in my .c and I'm not entirely sure why. From browsing it seems most people were missing a { or ( or ; etc somewhere, but I'm fairly certain I am not.
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
#include "Assembler.h"
int main(int argc, char** argv) {
// ...
preprocessText(file, inter1);
// ...
}
public void preprocessText(FILE* file, FILE* file2) { //error happens at this declaration
// ...
}
My header file is:
#ifndef ASSEMBLER_H
#define ASSEMBLER_H
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stddef.h>
// ...
void preprocessText(FILE* file, FILE* file2);
#endif
All methods are implicitly accessible by any other piece of code, if the function name is in scope. There is no public keyword in c
You have 'public' before 'void'. Remember, this is C ;)

Resources