ncurses error on windows 8.1 when compiling - c

I am just completely lost while trying to compile a simple ncurces demo program in c. It looks like some kind of linker error and it happens no matter what flags I pass to gcc on Windows / Cygwin
> /cygdrive/c/Users/me/Documents/demo.c:4:30: warning: unused parameter ‘argv’ [-Wunused-parameter]
int main(int argc, char *argv[]){
^
/tmp/cc6mTQ2P.o:demo.c:(.text+0x15): undefined reference to `initscr'
/tmp/cc6mTQ2P.o:demo.c:(.text+0x15): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `initscr'
/tmp/cc6mTQ2P.o:demo.c:(.text+0x1a): undefined reference to `noecho'
/tmp/cc6mTQ2P.o:demo.c:(.text+0x1a): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `noecho'
/tmp/cc6mTQ2P.o:demo.c:(.text+0x24): undefined reference to `curs_set'
/tmp/cc6mTQ2P.o:demo.c:(.text+0x24): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `curs_set'
/tmp/cc6mTQ2P.o:demo.c:(.text+0x33): undefined reference to `endwin'
/tmp/cc6mTQ2P.o:demo.c:(.text+0x33): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `endwin'
collect2: error: ld returned 1 exit status
enter code here

in order to resolve this error try using the -lncurses flag added to your gcc compiler arguments.

Related

gcc undefined reference to header of multiple files

I have a sample code temp.c:
#include "win.h"
win.h is in /home/me/Documents/Code/libs/TUI/win.h and has all the declared functions
which functions are defined in some files in /home/me/Documents/Code/libs/TUI/win/[lots of files].c which every file starts with
#include "../win.h"
//functions
So while using gcc -I /home/me/Documents/Code/libs/TUI /home/me/Documents/Code/temp.c -o /home/me/Documents/Code/temp, gcc returns every function used in temp.c declared in win.h as undefined
Exact output:
gcc -g -I/home/me/Documents/Code/libs/TUI /home/me/Documents/Code/temp.c -o /home/pk/Documents/Code/temp
/usr/bin/ld: /tmp/cc4berEn.o: in function `main':
/home/me/Documents/Code/temp.c:8: undefined reference to `innit'
/usr/bin/ld: /home/me/Documents/Code/temp.c:11: undefined reference to `newTable'
/usr/bin/ld: /home/me/Documents/Code/temp.c:13: undefined reference to `tableSetHeaders'
/usr/bin/ld: /home/me/Documents/Code/temp.c:35: undefined reference to `tableAppendRow'
/usr/bin/ld: /home/me/Documents/Code/temp.c:45: undefined reference to `printTable'
collect2: error: ld returned 1 exit status
notes
Using -I /home/me/Documents/Code/libs/TUI/win.h returns fatal error: win.h: No such file or directory 3 | #include "win.h"
/home/me/Documents/Code/libs/TUI is a folder
Writing every source file's name is not an option
Already tried this
-g for debug

Problem while running the example program from CFITSIO Quick Start Guide

I'm trying to work with the CFITSIO library to process FITS images in C. I followed the installation guide from the documentation and I checked that it was successful installed. However when I compile the following code:
#include <string.h>
#include <stdio.h>
#include "fitsio.h"
int main(int argc, char *argv[])
{
fitsfile *fptr;
char card[FLEN_CARD];
int status = 0, nkeys, ii; /* MUST initialize status */
fits_open_file(&fptr, argv[1], READONLY, &status);
fits_get_hdrspace(fptr, &nkeys, NULL, &status);
for (ii = 1; ii <= nkeys; ii++) {
fits_read_record(fptr, ii, card, &status); /* read keyword */
printf("%s\n", card);
}
printf("END\n\n"); /* terminate listing with END */
fits_close_file(fptr, &status);
if (status) /* print any error messages */
fits_report_error(stderr, status);
return(status);
}
I get the following error:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/libcfitsio.a(zcompress.o): in function `uncompress2mem':
/home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:97: undefined reference to `inflateInit2_'
/usr/bin/ld: /home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:117: undefined reference to `inflate'
/usr/bin/ld: /home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:117: undefined reference to `inflate'
/usr/bin/ld: /home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:176: undefined reference to `inflateEnd'
/usr/bin/ld: /home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:154: undefined reference to `inflateEnd'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/libcfitsio.a(zcompress.o): in function `uncompress2mem_from_mem':
/home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:209: undefined reference to `inflateInit2_'
/usr/bin/ld: /home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:220: undefined reference to `inflate'
/usr/bin/ld: /home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:251: undefined reference to `inflateEnd'
/usr/bin/ld: /home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:229: undefined reference to `inflateEnd'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/libcfitsio.a(zcompress.o): in function `uncompress2file':
/home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:291: undefined reference to `inflateInit2_'
/usr/bin/ld: /home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:312: undefined reference to `inflate'
/usr/bin/ld: /home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:356: undefined reference to `inflateEnd'
/usr/bin/ld: /home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:346: undefined reference to `inflateEnd'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/libcfitsio.a(zcompress.o): in function `compress2mem_from_mem':
/home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:391: undefined reference to `deflateInit2_'
/usr/bin/ld: /home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:404: undefined reference to `deflate'
/usr/bin/ld: /home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:435: undefined reference to `deflateEnd'
/usr/bin/ld: /home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:413: undefined reference to `deflateEnd'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/libcfitsio.a(zcompress.o): in function `compress2file_from_mem':
/home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:473: undefined reference to `deflateInit2_'
/usr/bin/ld: /home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:486: undefined reference to `deflate'
/usr/bin/ld: /home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:526: undefined reference to `deflateEnd'
/usr/bin/ld: /home/tres-2b/Desktop/cfitsio-4.0.0/zcompress.c:514: undefined reference to `deflateEnd'
collect2: error: ld returned 1 exit status
I tried passing the files as an argument on the command terminal and hard forcing a FITS file into the program, but still wasn't able to run the program successfully. I couldn't find a lot of information about this library, so any help would be appreciated.

LLVM: object file relocation truncated to fit: R_X86_64_32S against `.rodata'

I have an LLVM program that evaluates instructions and builds IR. I then emit the module using LLVMTargetMachineEmitToFile. When linking with ld I get an outut of:
test:(.text+0x61): relocation truncated to fit: R_X86_64_32S against `.rodata'
test:(.text+0x6d): relocation truncated to fit: R_X86_64_32S against `.rodata'+4
collect2: error: ld returned 1 exit status
The cause of this error comes from a global variable I create in the program. When outputting the IR you see:
#const.array = private unnamed_addr constant [6 x i8] c"\05\06\07\08\09\0A", align 16
The code I use to output the object file:
LLVMTargetRef t;
LLVMGetTargetFromTriple(LLVMGetDefaultTargetTriple(), &t, &error);
if (error)
printf("%s\n", error);
LLVMTargetMachineRef target = LLVMCreateTargetMachine(t, LLVMGetDefaultTargetTriple(), LLVMGetTargetName(t), LLVMGetHostCPUFeatures(), LLVMCodeGenLevelNone, LLVMRelocStatic, LLVMCodeModelDefault);
strcpy(file_name + len, ".o\0");
LLVMTargetMachineEmitToFile(target, mod, file_name, LLVMObjectFile, &error);
I'm using ld provided by cygwin. If I use ld in WSL it links fine. Also I tried using the -m option with ld but the cygwin version only seems to supprt i386 for some reason. I've tried different relocation modes in LLVMCreateTargetMachine but that didn't seem to do anything. How can I fix this?
Also a side question: When using LLVMConsArray it produces an ascii string as seen above but when I emit IR code for a c file in clang it uses an actual array. Can this be fixed?

OpenCL compilation issue

I am new to Opencl Programming. I have written a matrix multiplication program while compiling it is giving me error
My include files are:
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
#include <CL/cl.h>
#include <stdbool.h>
But I got an error as:
/usr/bin/ld: /tmp/ccxNPkyU.o: in function `main':
gmm.c:(.text+0x2d3): undefined reference to `clGetPlatformIDs'
/usr/bin/ld: gmm.c:(.text+0x2ef): undefined reference to `clGetPlatformIDs'
/usr/bin/ld: gmm.c:(.text+0x322): undefined reference to `clGetDeviceIDs'
/usr/bin/ld: gmm.c:(.text+0x376): undefined reference to `clCreateContext'
/usr/bin/ld: gmm.c:(.text+0x527): undefined reference to `clCreateCommandQueue'
/usr/bin/ld: gmm.c:(.text+0x5ab): undefined reference to `clCreateProgramWithSource'
/usr/bin/ld: gmm.c:(.text+0x5fc): undefined reference to `clBuildProgram'
/usr/bin/ld: gmm.c:(.text+0x64c): undefined reference to `clGetProgramBuildInfo'
/usr/bin/ld: gmm.c:(.text+0x682): undefined reference to `clCreateKernel'
/usr/bin/ld: gmm.c:(.text+0x6dc): undefined reference to `clCreateBuffer'
/usr/bin/ld: gmm.c:(.text+0x70c): undefined reference to `clCreateBuffer'
/usr/bin/ld: gmm.c:(.text+0x73c): undefined reference to `clCreateBuffer'
/usr/bin/ld: gmm.c:(.text+0x76e): undefined reference to `clCreateBuffer'
/usr/bin/ld: gmm.c:(.text+0x7a0): undefined reference to `clCreateBuffer'
/usr/bin/ld: /tmp/ccxNPkyU.o:gmm.c:(.text+0x7d2): more undefined references to `clCreateBuffer' follow
/usr/bin/ld: /tmp/ccxNPkyU.o: in function `main':
gmm.c:(.text+0x84c): undefined reference to `clSetKernelArg'
/usr/bin/ld: gmm.c:(.text+0x875): undefined reference to `clSetKernelArg'
/usr/bin/ld: gmm.c:(.text+0x89e): undefined reference to `clSetKernelArg'
/usr/bin/ld: gmm.c:(.text+0x8c7): undefined reference to `clSetKernelArg'
/usr/bin/ld: gmm.c:(.text+0x8f8): undefined reference to `clSetKernelArg'
/usr/bin/ld: /tmp/ccxNPkyU.o:gmm.c:(.text+0x929): more undefined references to `clSetKernelArg' follow
/usr/bin/ld: /tmp/ccxNPkyU.o: in function `main':
gmm.c:(.text+0xa58): undefined reference to `clEnqueueReadBuffer'
/usr/bin/ld: gmm.c:(.text+0xa9f): undefined reference to `clEnqueueReadBuffer'
/usr/bin/ld: gmm.c:(.text+0xae6): undefined reference to `clEnqueueReadBuffer'
/usr/bin/ld: gmm.c:(.text+0xb04): undefined reference to `clWaitForEvents'
/usr/bin/ld: gmm.c:(.text+0xb13): undefined reference to `clFinish'
/usr/bin/ld: gmm.c:(.text+0xb3c): undefined reference to `clGetEventProfilingInfo'
/usr/bin/ld: gmm.c:(.text+0xb65): undefined reference to `clGetEventProfilingInfo'
/usr/bin/ld: gmm.c:(.text+0xc9f): undefined reference to `clReleaseMemObject'
/usr/bin/ld: gmm.c:(.text+0xcae): undefined reference to `clReleaseMemObject'
/usr/bin/ld: gmm.c:(.text+0xcbd): undefined reference to `clReleaseMemObject'
/usr/bin/ld: gmm.c:(.text+0xccc): undefined reference to `clReleaseMemObject'
/usr/bin/ld: gmm.c:(.text+0xcdb): undefined reference to `clReleaseMemObject'
/usr/bin/ld: /tmp/ccxNPkyU.o:gmm.c:(.text+0xcea): more undefined references to `clReleaseMemObject' follow
collect2: error: ld returned 1 exit status
I am compiling program by this statement:gcc -o gmmc gmm.c. Can anyone help me
Link your program with the OpenCL library:
gcc -O2 -Wall -o gmmc gmmc.c -lOpenCL
If this doesn't find the library, you need to pass the path to it:
gcc -O2 -Wall -o gmmc gmmc.c -L/insert/path/here -lOpenCL
where /insert/path/here is the directory that contains libOpenCL.so. You can search a directory for it, e.g.
find /usr/lib -name libOpenCL.so

cygwin make - undefined referance to INT_MAX and argp_usage

I've not written this program myself nor am I experienced with cygwin and linux but from what I can tell the file seems to have the right include:
// tsim_argp.c
#include <argp.h>
#include <stdlib.h>
#include <unistd.h> /* nice */
#include "tsim_argp.h"
argp.h which contains argp_usage also got limits.h included which contains INT_MAX so what exactly am I missing? I got all the other c-files compiling just fine it's just this last one that's causing problem.
make dialogue:
...
Making all in src
make[2]: Entering directory '/cygdrive/c/Users/David/Downloads/tsim-0.84/src'
gcc -DHAVE_CONFIG_H -I. -I.. -std=gnu99 -pedantic -Wall -Wextra -Wmissing-pro
totypes -DRESDIR=\"/c/Users/David/Downloads/Train_Simulator/share/tsim\" -g -O2
-MT tsim-tsim_argp.o -MD -MP -MF .deps/tsim-tsim_argp.Tpo -c -o tsim-tsim_argp.o
`test -f 'tsim_argp.c' || echo './'`tsim_argp.c
tsim_argp.c: In function 'setpriority':
tsim_argp.c:170:19: error: 'INT_MAX' undeclared (first use in this function)
if( priority == INT_MAX ) {
^
tsim_argp.c:170:19: note: each undeclared identifier is reported only once for e
ach function it appears in
...
Makefile:479: recipe for target 'tsim-tsim_argp.o' failed
make[2]: *** [tsim-tsim_argp.o] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/David/Downloads/tsim-0.84/src'
Makefile:247: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/cygdrive/c/Users/David/Downloads/tsim-0.84'
Makefile:169: recipe for target 'all' failed
make: *** [all] Error 2
make dialogue if I include the limits.h library directly in tsim_argp:
...
Making all in src
make[2]: Entering directory '/cygdrive/c/Users/David/Downloads/tsim-0.84/src'
gcc -std=gnu99 -pedantic -Wall -Wextra -Wmissing-prototypes -DRESDIR=\"/c/Users/
David/Downloads/Train_Simulator/share/tsim\" -g -O2 -L/usr/X11R6/lib -lXaw -lXt
-lXmu -lX11 -lXext -o tsim.exe tsim-AddToggleWidget.o tsim-DialogPopup.o tsim-f
ile.o tsim-resources.o tsim-timer.o tsim-tsim.o tsim-bitmap.o tsim-DrawingPalett
e.o tsim-Graph.o tsim-sound.o tsim-train.o tsim-BitmapDirectory.o tsim-errcheck.
o tsim-pipe.o tsim-Sprite.o tsim-tsim_argp.o -lXt -lXmu -lXext -lXaw -lX11
tsim-tsim_argp.o: In function `parse_opt':
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:113: undefined refer
ence to `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:113:(.text+0xbe): re
location truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:83: undefined refere
nce to `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:83:(.text+0x10e): re
location truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:98: undefined refere
nce to `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:98:(.text+0x15c): re
location truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:68: undefined refere
nce to `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:68:(.text+0x1a3): re
location truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:118: undefined refer
ence to `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:118:(.text+0x294): r
elocation truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
tsim-tsim_argp.o:/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:103
: more undefined references to `argp_usage' follow
tsim-tsim_argp.o: In function `parse_opt':
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:103:(.text+0x2c4): r
elocation truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:73:(.text+0x2f4): re
location truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:88:(.text+0x324): re
location truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:127:(.text+0x354): r
elocation truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
tsim-tsim_argp.o: In function `parse':
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:234: undefined refer
ence to `argp_parse'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:234:(.text+0x429): r
elocation truncated to fit: R_X86_64_PC32 against undefined symbol `argp_parse'
collect2: error: ld returned 1 exit status
Makefile:228: recipe for target 'tsim.exe' failed
make[2]: *** [tsim.exe] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/David/Downloads/tsim-0.84/src'
Makefile:247: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/cygdrive/c/Users/David/Downloads/tsim-0.84'
Makefile:169: recipe for target 'all' failed
make: *** [all] Error 2
In Cygwin, it looks like argp is separate library. You'll need to add: -largp to your gcc line.

Resources