SDL2 is not seeing X11/Video Device correctly - c

(I am aware there is a great deal of documentation on the subject, but I am either too inexperienced to find the one that works or I have a different problem than the one documented)
I am trying to load up a simple SDL wrapper that I wrote on my Mac on Linux (Lubuntu 20.04, LXQt 0.14.1). However when SDL_Init(SDL_INIT_VIDEO) is called, the following SDL_Error() return statement is generated: No available video device. I have verified that my DISPLAY envvar is set to :0 (which is correct according to xterm) and my SDL_VIDEODRIVER is unset.
Setting my SDL_VIDEODRIVER to x11 triggers this alternative error on init x11 not available.
I am rather stumped, the only possible conclusion I could draw from this is that I am somehow not using x11 or am going about this wrong.
Here is a minimal example that triggers this error:
#include <SDL2/SDL.h>
int main() {
SDL_Init(SDL_INIT_VIDEO);
printf("%s\n", SDL_GetError());
}
I really appreciate any help I can get!
I am using the libsdl2-dev apt package for SDL2

Turns out that I had forgotten to link X11 during compilation which caused SDL_VIDEO to fail to initialise. This was resolved by using -lX11.
Thank you for the help!

Related

I cant use auxiliary functions from zephyr ( tty.h) file

I am building a project and I have the board stm nucleo_l496zg. All i want to do is to use the drivers from the board in order to communicate the board after west flash with minicom, it is a simple string transfer and response program. I am building this project with zephyr and my issue is that I cant use the functions tty_init , tty_read and tty_set_rx_buf despite that I use the proper include " #include <console/tty.h> ". The compiler returns an undefined reference to thoose three functions but in my program I am using another one function from tty.h header which is tty_set_timeout but at this function it doesnt say nothing. Though I notiched in that in here(documentation of tty.h) tty_Set_timeout is the only function that has something inside. I cant understand why I am getting that please if someone can help me let me know !
I had the same problem and I solve it by adding those lines to my .conf file:
CONFIG_SERIAL=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETCHAR=y
And don't forget to mention the file (.conf file) also in your CMakeList.txt file:
set(CONF_FILE ***.conf)
Hope that it will work with you as well

Unable to print debug messages in sicslowmac.c

I have set #define DEBUG 1 in sicslowmac.c
but the debug messages are not being printed in packet capture display of
cooja simulator. I have tried using printf in every function of sicslowmac.c. Also tried #define DEBUG DEBUG_PRINT but no success.
I have used sky motes for udp-server.c and udp-client.c in
rpl-udp. I
am using latest build of contiki. What might I be doing wrong?
I am able to print debug messages from cc2420.c and sicslowpan.c but not from sicslowmac.c.
P.S: I have not made even a single change to any of the other files. So let not the question be treated as too broad or primarily opinion-based.
I got help from contiki mailing list.
We need to tell contiki which RDC driver to use. By default it is nullrdc_driver. I changed it to sicslowmac_driver.
But then I got undefined reference to sicslowmac_driver in contiki-sky-main.c of sky platform. I could solve it by adding core/net/mac/sicslowmac in Modules of Makefile.sky.

codeblocks autocomplete / calltips not working for C standard library functions

I'm trying to start using code::blocks to do some C programming in just to learn. I was hoping to use the codecompletion / calltips feature (e.g. when typing say "printf" it popsup a handy dropdown box that shows the parameters.
I've made a new project and a new file in that project called "hello.c"
#include <stdio.h>
int main(){
int test=0;
printf("%d",test);
return 0;
}
but midway through typing prin---only "priority_queue and private" show up, no printf functions, and nothing happens when pressing ctrl-j, ctrl-space, alt-shift-space, ctrl-n or p nothing works. I've tried reparsing the project. I initially had 13.12 version installed because that's what Ubuntu (14.04.4LTS) had but then I installed version 16.01 by mucking with the apt-get ppas. That version also doesn't work. I've tried disabling and reenabling the code completion plugin and I've made sure under settings->editor-> that code completion box is checked.
What am I doing wrong here? Any help would be very appreciated. Thanks so much!
The new Code::Blocks IDE is not so polished on Ubuntu yet. You can try reinstalling it. And if it didn't work try reverting to 13.12.

C equivalent to applescript "tell X to open Y"

Does anybody have a C library function that does the equivalent of AppleScript "Tell application X to open Y"? I'm not using cocoa, just plain old C, and ideally I would like to be able to do this from a commandl ine application that has no GUI interface.
This doesn't have to be fancy, it would be all right if I don't even wait for the success-or-failure response. Just needs to send the right Apple event.
I think by far the simplest solution would be to issue a system call to the osascript command line utility.
#include <stdio.h>
#include <stdlib.h>
int main(void) {
system("osascript -e 'tell application \"X\" to open POSIX file \"/path/to/Y\"'");
return 0;
}
OP's kinda creating a rod for his own back here, as except for CoreFoundation most OS X-specific C APIs are now legacy/deprecated. Used to be you could call LaunchServices' LSOpenApplication(), but that got deprecated in 10.10.
If NSWorkspace isn't an option then use open via fork() and execv(), which allows arguments to be passed directly.
Thanks for the helpful thoughts, they really got me pointed in the right direction. Here's the synthesis of these answers that seems to be working well for me, code that assumes that the path and the filename will be variable:
char wdname[1000], obuf[1000];
const char* filename = "WavySwirl.stl";
getwd(wdname);
sprintf(obuf, "open %s/%s", wdname, filename);
system(obuf);

Code::Blocks 13.12 error - CC1.exe has stopped working

I am using Code::Blocks 13.12 for programming in C. After building and running my simple HelloWorld.c program, it gives an error.
Error: An alert box pop up saying -"cc1.exe has stopped working.A problem caused the program to stop working correctly.Windows will close the program and notify you if a solution is available."
I tried using Notepad++ , the same pop up appears saying a.exe has stopped working.
I am a naive,so have no idea on how to deal with this.
My queries:
1) Am I using an outdated version? If not, how can I get rid of this problem?
2) Which is the most efficient IDE available for C/C++ if Code::Blocks is not that efficient?
My requirement"
-I had been using Turbo C and it doesn't give errors like segmentation fault and other memory related errors that we get in online Compilers or compilers of competitive programming.So, I need an efficient compiler which behaves same as online compilers, so I don't get stuck while solving problems during competitive programming.
This is the simple code giving error:
#include <stdio.h>
void main()
{
printf("Hello world!");
//return 0;
}
Edit:
Even after changing the code to return int, it's giving an error.I tried editing the code as below, but the same window is being popped up again.
int main(void)
{
printf("Hello world!");
return 0;
}
There's no problem with your code, though indeed, as pointed out in the comments, neither void main() nor int main(void) is considered correct, but that's not what's causing the problem. cc1.exe is a MinGW-related file (MinGW is the GCC port for Windows that Code::Blocks uses by default for compilation); if it's crashing, it's possible the installation is corrupt.
I suggest you try reinstalling MinGW - remove Code::Blocks, install the standalone MinGW version, then download Code::Blocks without the compiler suite, install it and configure to use your version of MinGW.
For me, the solution was to choose,
Select target -> Release
from the Build menu. It took lots of time for me to find this!

Resources