Cross compiling pdcurses from arch linux to windows - c

I'm trying to cross-compile a simple "Hello World!" program, from arch linux to windows
Here's the code:
#include <stdio.h>
#include <curses.h>
int main() {
initscr();
printw("Hello World!");
refresh();
getch();
endwin();
return 0;
}
And then I compile using mingw:
x86_64-w64-mingw32-gcc hello.c -o hello-x64.exe -lpdcurses.dll
And when I run the program, it crashes. Here's it's trace

Make sure you're including the curses.h from the PDCurses package, and not the system curses.h (which is ncurses).
Also, although it's probably not relevant to the problem, stdio.h is not needed here.

Related

Why am I getting the error "undefined reference to main" even though main is properly defined?

I am running Xubuntu on a vm (because it was easier to do that compared to getting gcc on windows).
I have tried all of the different arguments for compiling the program (eg. running gcc filename.c and gcc filename.c -o filename), but none of them have changed the outcome.
My code is:
#include <stdio.h>
int main(void) {
printf("a");
return 0;
}
I've tried using main() and main(arg...[or whatever it is I can't remember]) and I get the same error.

Compiling C on Windows with gcc ... -lWs2_32

I am wanting to compile c through the command prompt on Windows.
I have the following file main.c:
#include <stdio.h>
#ifdef _WIN32
int main () {
printf("Windows\n");
return 0;
}
#else
int main () {
printf("*nix\n");
return 0;
}
#endif
And I follow these steps:
open cmd
$ gcc -o testprog.exe main.c -lWs2_32
$ testprog.exe
Output is *nix
I have installed MinGW and setup the path to gcc. I have also tried using __MINGW32__. What do I need to do?

C program for MIPS74kc never returns

I have a simple C "Hello world" program, compiled using GCC toolchain for mips74-kc running a Linux S/O (kernel 3.10.36)
#include <stdio.h>
int main() {
printf("Hello world\n");
return 0;
}
The program is compiled on a x64-86 Ubuntu machine, as I don't have GCC available on the MIPS machine. I compile the program with the static linking flag.
mips-linux-gnu-gcc --verbose -static -march=74kc main.c -o main
When I launch the program on the MIPS processor, the program holds and never returns, consuming 100 % of the CPU.
Does anyone have a clue on why this could happen?

Print a wide unicode character with ncurses

I'm trying to position a star unicode character on screen using the ncurses.h library in C on Ubuntu. The code I'm trying to run is the following:
#include <stdio.h>
#include <wchar.h>
#include <curses.h>
#include <ncurses.h>
#include <stdlib.h>
#include <wctype.h>
#include <locale.h>
int main() {
setlocale(LC_CTYPE, "");
initscr();
cbreak();
WINDOW *win = newwin(0, 0, 0, 0);
refresh();
wrefresh(win);
const wchar_t* star = L"0x2605";
mvaddwstr(3, 3, star);
getch();
endwin();
}
But I keep getting the error
implicit declaration of function ‘mvaddwstr’ [-Wimplicit-function-declaration]
Despite this function being well documented here together with similar functions which I can't get to work either. Is there some library I'm not including to make this work? or is there an alternative way to go about displaying this character? I appreciate any help.
You must be compiling against the "narrow" curses (ncurses vs ncursesw)
I was able to compile your example on ubuntu 16.04 with the following:
apt install libncursesw5-dev
# --cflags expanded to: -D_GNU_SOURCE -I/usr/include/ncursesw
gcc main.c $(ncursesw5-config --cflags) -c
# --libs expanded to: -lncursesw -ltinfo
gcc main.o $(ncursesw5-config --libs) -o main
And then
./main
I had to make the following diff to your example code as well:
- const wchar_t* star = L"0x2605";
+ const wchar_t* star = L"\x2605";

How do you successfully compile a C program using the GNU Readline library?

I followed the instructions to install GNU Readline, as well as Curses, however I get some linker issues that I am unsure how to resolve. The following is my program:
main.c
#include <stdio.h>
#include <stdlib.h>
#include <curses.h>
#include <term.h>
#include <readline/readline.h>
#include <readline/history.h>
int main()
{
char * line = readline ("Enter a line: ");
free (line);
return 0;
}
I compiled using: gcc -o main {,.c} -lreadline -lncurses (and the readline includes were where they were supposed to be, in usr/includes...
Running main gave me:
./main: symbol lookup error: /usr/local/lib/libreadline.so.6: undefined symbol: UP
Any direction as to go about resolving this would be greatly appreciated.
sudo apt-get install libreadline6-dev
gcc -o main {,.c} -lreadline -lncurses

Resources