I'm writing a C program and GCC doesn't recognise WIFCONTINUED. I've included the library that contains it (sys/wait.h) and checked that the library does exist on my machine.
My program:
#include <stdio.h>
#include <linux/limits.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include "LineParser.h"
//Some code...
if(WIFCONTINUED(status)){
temp->status = RUNNING;
}
//More code...
The error I get when I compile is:
warning: implicit declaration of function ‘WIFCONTINUED’; did you mean ‘__W_CONTINUED’? [-Wimplicit-function-declaration]
else if(WIFCONTINUED(status)){
^~~~~~~~~~~~
__W_CONTINUED
undefined reference to `WIFCONTINUED'
collect2: error: ld returned 1 exit status
Has anyone experienced a similar problem with WIFCONTINUED?
EDIT:
Here is some example(not my original program) that failes to compile with the same errros:
#include <stdio.h>
#include <linux/limits.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
int main(int argc,char** argv){
int status;
if(WIFCONTINUED(status)){
printf("Works");
}
return 0;
}
My OS is Ubuntu 18.04 and my makefile is:
all: rep
rep: rep.o
gcc -g -Wall -m32 rep.o -o rep
rep.o: rep.c
gcc -g -Wall -m32 -ansi -c -o rep.o rep.c
.PHONY : clean
clean :
-rm -f *.o
The cause is the -ansi flag. It's equivalent to -std=c90 and WIFCONTINUED is not part of the C standard.
Most of the system programming headers you have included are from POSIX. So -ansi isn't going to help with anything at all. Just dropping the flag -ansi would be sufficient to fix this.
Related
I'm trying to compile a project that contains different modules (.h files) so I'm using a makefile. I added a new module called semaphore_v2.h which I included in another module called connection.h. connection.h is included into jack.c where the main process is. When compiling using make command, I get the following error:
Seems like despite I included the module, it doesn't keep track of the references of the semaphore_v2.h module and I can't find the issue here. What's wrong?
makefile:
all: compilation
jack.o: jack.c
gcc -c jack.c -Wall -Wextra
semaphore_v2.o: semaphore_v2.c semaphore_v2.h
gcc -c semaphore_v2.c -Wall -Wextra
files.o: files.c files.h
gcc -c files.c -Wall -Wextra
connection.o: connection.c connection.h
gcc -c connection.c -Wall -Wextra
compilation: jack.o files.o connection.o
gcc jack.o connection.o files.o -o jack -Wall -Wextra -lpthread
connection.h
#ifndef _CONNECTION_H_
#define _CONNECTION_H_
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <time.h>
#include "files.h"
#include <ctype.h>
#include <pthread.h>
#include <sys/wait.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include "semaphore_v2.h"
typedef struct {
int socketfd;
int memid;
semaphore *sinc;
}thread_input;
...
jack.c
#include <signal.h>
#include "connection.h"
...
You should change your makefile compilation target to include also semaphore_v2.o
so you should have such a line at your makefile:
compilation: jack.o files.o connection.o semaphore_v2.o
gcc jack.o connection.o files.o semaphore_v2.o -o jack -Wall -Wextra -lpthread
Note semaphore_v2.o appears twice, one time as a dependency to this target and one time as input to the gcc command.
So I'm trying to include some headers in a c file on ubuntu16.04.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include "list.h"
#include "phypages.h"
#include "pagetable.h"
It has the error:
fatal error: list.h: No such file or directory
I found all linux header files are in the
/usr/src/linux-headers-4.4.0-164/include/linux
So I use -I to include
gcc XXX.c -o XXX -I/usr/src/linux-headers-4.4.0-164/include/linux
But then has the error
/usr/src/linux-headers-4.4.0-164/include/linux/stddef.h:4:31: fatal error: uapi/linux/stddef.h: No such file or directory
Can anyone help? Thank you!
Suggest using;
gcc XXX.c -o XXX -I/usr/include -I/usr/src/linux-headers-4.4.0-164/include/linux
so the 'normal' C header files are searched before searching the linux header files
Maybe it #include<list.h>, not #include"list.h"?
Output of make all:
make all
Building file: ../webrtc.c
Invoking: Cross GCC Compiler
gcc -std=c99 -I/opt/openwebrtc-0.3/include/ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -O0 -g3 -Wall -c -fmessage-length=0 -ansi -MMD -MP -MF"webrtc.d" -MT"webrtc.o" -o "webrtc.o" "../webrtc.c"
Finished building: ../webrtc.c
Building target: WebRTC
Invoking: Cross GCC Linker
gcc ./webrtc.o -lglib-2.0 -lsctp -o "WebRTC" -L/opt/openwebrtc-0.3/lib -L/usr/lib/x86_64-linux-gnu/glib-2.0/include -L/usr/include/glib-2.0
./webrtc.o: In function `startServer':
/home/sn/workspace/cpp/praktikum/WebRTC/Debug/../webrtc.c:17: undefined reference to `owr_init'
/home/sn/workspace/cpp/praktikum/WebRTC/Debug/../webrtc.c:18: undefined reference to `owr_run_in_background'
collect2: error: ld returned 1 exit status
makefile:32: recipe for target 'WebRTC' failed
make: *** [WebRTC] Error 1
webrtc.c:
#include "webrtc.h"
int main(void)
{
/*startClient();*/
startServer();
return EXIT_SUCCESS;
}
void startServer(void)
{
printf("Initializing OpenWebRTC");
owr_init(NULL);
owr_run_in_background();
}
webrtc.h:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <ctype.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <pthread.h>
#include <owr/owr.h>
#include <owr/owr_data_channel.h>
#include <owr/owr_crypto_utils.h>
#include <owr/owr_types.h>
/* Defines:*/
#define MAX_BUFFER 1024
#define SERVER_PORT_NUMBER 65300
#define SERVER_BIND_ADDR "127.0.0.1"
/* Prototypes: */
void startServer(void);
Output of file:
libopenwebrtc.so.4201.0.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=3a9726e870736687b14c1dca326bda336fb2d088, stripped
I've build OpenWebRTC as stated in the wiki located here on Debian 8 and installed the generated .deb files. In Eclipse I've included the header files (/opt/openwebrtc-0.3/include) and the libs (/opt/openwebrtc-0.3/lib) and it is still not working. I've also uploaded the generated deb files into my apt repository
sources.list:
deb http://openwebrtc.niehus.eu/apt/debian/ jessie main
Try to change
gcc ./webrtc.o -lglib-2.0 -lsctp -o "WebRTC" -L/opt/openwebrtc-0.3/lib -L/usr/lib/x86_64-linux-gnu/glib-2.0/include -L/usr/include/glib-2.0
to
gcc ./webrtc.o -lglib-2.0 -lsctp -lopenwebrtc -o "WebRTC" -L/opt/openwebrtc-0.3/lib -L/usr/lib/x86_64-linux-gnu/glib-2.0/include -L/usr/include/glib-2.0
The problem might be that you are not linking necessary library.
I get the error unknown type name 'uint32_t' and included stdint.h. uint8_t doesn't produce an error, neither does uint16_t.
I'm using MinGW and the following make-lines:
# Build for Windows under MinGW
#MINGWDBG= -DDEBUG -O0
MINGWDBG= -DNDEBUG -Os
#MINGWOPT= -W -Wall -mthreads -Wl,--subsystem,console $(MINGWDBG) -DHAVE_STDINT
MINGWOPT= -W -Wall -mthreads -Wl,--subsystem,windows $(MINGWDBG)
mingw:
windres win32\res.rc win32\res.o
gcc $(MINGWOPT) mongoose.c -lws2_32 \
-shared -Wl,--out-implib=$(PROG).lib -o $(PROG).dll
gcc $(MINGWOPT) mongoose.c main.c win32\res.o -lws2_32 -ladvapi32 \
-o $(PROG).exe
Code:
uint32_t function(void) {
return VALUE;
}
And the includes:
#include <stdio.h>
#include <string.h>
#include "mongoose.h"
#include "main.h"
#include <stdint.h>
To answer my own question, changing the order of the includes seemed to do the trick.
If
#include "main.h"
#include <stdint.h>
didn't work, but
#include <stdint.h>
#include "main.h"
did, it is likely that your main.h file relies on stdint.h. That means you should add #include <stdint.h> to main.h.
When I try to use LD_PRELOAD as following,
LD_PRELOAD=getpid.so ./testpid
I get the following error...
ERROR: ld.so: object 'getpid.so' from LD_PRELOAD cannot be preloaded: ignored.
I compile getpid.so by using
gcc -Wall -fPIC -shared -o getpid.so getpid.c
and it contains the following code...
// getpid.c
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
pid_t getpid(void)
{
printf("Hello, world!\n");
return syscall(SYS_getpid);
}
tespid.c constains code which uses getpid as shown below and which is compiled by doing
gcc testpid -o testpid.c
What can be the problem here? Why is LD_PRELOAD not working?
// testpid.c
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
int main()
{
printf( "pid = %d!\n", getpid() );
return 0;
}
Looks like the loader is unable to find getpid.so as you've not mentioned the path to the library.
Try:
LD_PRELOAD=/full/path/to/getpid.so ./testpid
I was also facing error as below
ERROR: ld.so: object '/usr/lib64/libjemalloc.so.1' from LD_PRELOAD cannot be preloaded
Below were my steps resolved the error for me.
Go to the path /usr/lib64 and look for the libjemalloc using below commands*
#cd /usr/lib64
#ls | grep libjemalloc
if you don't find you don't have that package installed in your system
$sudo yum whatprovides libjemalloc*
$sudo yum install jemalloc-3.6.0-1.amzn2.x86_64