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.
Related
How can I fix this error in mingw64?
gcc -O2 -Wall -g -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -MMD -D_GNU_SOURCE -DCONFIG_VERSION=\"2019-12-21\" -DCONFIG_SLIRP -DCONFIG_FS_NET -DCONFIG_SDL -DCONFIG_RISCV_MAX_XLEN=128 -DCONFIG_X86EMU -c -o temu.o temu.c
temu.c:39:10: fatal error: linux/if_tun.h: No such file or directory
39 | #include <linux/if_tun.h>
| ^~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:129: temu.o] Error 1
I'm trying to compile tinyemu.
It turns out I need to remove everything in a "#ifndef" area that is not supposed to be used on Windows.
#ifndef _WIN32
#include <termios.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <linux/if_tun.h>
#endif
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.
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.
When compiling my school project written in C I get following errors:
/tmp/ccFDQk9j.o: In function `main':
proj2.c:(.text+0x187): undefined reference to `sem_open' (several times)
proj2.c:(.text+0x35a): undefined reference to `sem_post' (several times)
proj2.c:(.text+0x381): undefined reference to `sem_wait' (several times)
proj2.c:(.text+0x6ec): undefined reference to `sem_close' (several times)
proj2.c:(.text+0xda6): undefined reference to `sem_unlink' (several times)
My libraries are:
#include <errno.h>
#include <fcntl.h>
#include <semaphore.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/wait.h>
#include <unistd.h>
#include <string.h>
#include <sys/sem.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <time.h>
And I am compiling using:
gcc -std=gnu99 -Wall -Wextra -Werror -pedantic proj2.c -o ext
Any ideas?
(Also I am ashamed to admit I put everything into one main. Yeah. Please don't stone me.)
EDIT:
So I adjusted my compilation settings to:
gcc -std=gnu99 -Wall -Wextra -Werror -pedantic -pthread proj2.c -o ext
And the amount of complaints has been reduced to these only two:
/tmp/cc51XZFK.o: In function `main':
proj2.c:(.text+0x249): undefined reference to `shm_open'
proj2.c:(.text+0xdf9): undefined reference to `shm_unlink'
collect2: ld returned 1 exit status
EDIT 2.0:
Same error mistake for
gcc -std=gnu99 -lrt -Wall -Wextra -Werror -pedantic -pthread proj2.c -o ext
EDIT 3.0:
Successfully compiled. Thank you Paul Griffiths and Joachim Isaksson.
gcc -std=gnu99 -Wall -Wextra -Werror -pedantic proj2.c -pthread -lrt -o ext
For sem_* functions, link with -pthread.
For shm_* functions, link with -lrt.
Probably you need to link with a library where those sem_* methods are.
-lpthread
I've been working on this for a while now. I have these files:
main.c
zSim.h
zSim.c
zDynamicArray.h
zDynamicArray.c
zOptions.h
zOptions.c
zMain.h
zMain.c
All of the files and headers are located within the same folder.
My main has the following includes:
#include "zDynamicArray.h"
#include "zOptions.h"
#include "zMain.h"
#include "zSim.h"
#include <stdio.h>
#include <math.h>
I am using header guards. Just for example, this is from my zSim.h file:
#ifndef SIM_H
#define SIM_H
#include "zDynamicArray.h"
#include "zOptions.h"
//This Header is accountable
//for all Simulation Related things.
int Simulate(SIMOPT so,PRINTOPT po);
#endif
and this is a snippet from my zSim.c code (maybe I am doing something wrong here?):
#define M_PI 3.14159265358979323846
#include "zSim.h"
#include "zDynamicArray.h"
#include "zOptions.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
I am compiling using this gcc command:
gcc main.c zSim.c zOptions.c zDynamicArray.c zMain.c -o TEST
and I also used:
cc -c main.c
cc -c zSim.c
cc -c ... etc
cc *.o -o TEST
They all result in an undefined reference for anything in the math.h library. Also when I use the gcc -I command, math is still undefined.
If i compile using gcc main.c, I get unresolved references for anything in my header files.
What should I do?
try ading -lm at the end : gcc -c main.c cc -c zSim.c cc -c ... etc cc *.o -o TEST -lm
You have to link the math library with the -lm option. The reason why is explained here : Why do you have to link the math library in C?
they all result in an undefined reference for anything in the math.h library
math.h is only the header file which contains prototypes and type declarations. You also need to link against the math library when creating your executable. Add -lm to your gcc call:
gcc main.c zSim.c zOptions.c zDynamicArray.c zMain.c -o TEST -lm
See also Undefined reference to `sin`.