After a battle trying to include ncurses in my project with makefile, when i try to make .o files it gaves me this errors:
In file included from C:/MinGW/x86_64-w64-mingw32/include/stddef.h:7,
from C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/stddef.h:1,
from C:/MinGW/include/stdint.h:54,
from C:/MinGW/include/ncursesw/curses.h:63,
from src/main.c:1:
C:/MinGW/x86_64-w64-mingw32/include/crtdefs.h:35:18: error: expected ';' before 'typedef'
__MINGW_EXTENSION typedef unsigned __int64 size_t;
^~~~~~~~
;
C:/MinGW/x86_64-w64-mingw32/include/crtdefs.h:45:18: error: expected ';' before 'typedef'
__MINGW_EXTENSION typedef __int64 ssize_t;
^~~~~~~~
;
C:/MinGW/x86_64-w64-mingw32/include/crtdefs.h:62:18: error: expected ';' before 'typedef'
__MINGW_EXTENSION typedef __int64 intptr_t;
^~~~~~~~
;
C:/MinGW/x86_64-w64-mingw32/include/crtdefs.h:75:18: error: expected ';' before 'typedef'
__MINGW_EXTENSION typedef unsigned __int64 uintptr_t;
^~~~~~~~
;
C:/MinGW/x86_64-w64-mingw32/include/crtdefs.h:88:18: error: expected ';' before 'typedef'
__MINGW_EXTENSION typedef __int64 ptrdiff_t;
^~~~~~~~
;
C:/MinGW/x86_64-w64-mingw32/include/crtdefs.h:123:18: error: expected ';' before 'typedef'
__MINGW_EXTENSION typedef __int64 __time64_t;
^~~~~~~~
;
In file included from C:/MinGW/include/stdio.h:94,
from C:/MinGW/include/ncursesw/curses.h:164,
from src/main.c:1:
C:/MinGW/include/sys/types.h:123:21: error: conflicting types for 'ssize_t'
typedef _ssize_t ssize_t;
^~~~~~~
In file included from C:/MinGW/x86_64-w64-mingw32/include/stddef.h:7,
from C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/stddef.h:1,
from C:/MinGW/include/stdint.h:54,
from C:/MinGW/include/ncursesw/curses.h:63,
from src/main.c:1:
C:/MinGW/x86_64-w64-mingw32/include/crtdefs.h:45:35: note: previous declaration of 'ssize_t' was here
__MINGW_EXTENSION typedef __int64 ssize_t;
This is my makefile:
PROJECT=ProjectName
CC=gcc
CFLAGS=-Wall -std=c11
CPPFLAGS = -MMD -MP
CFLAGS = -Wall $(INC) -g3
LIBS = -L"C:/MinGW/lib" -L"C:/MinGW/x86_64-w64-mingw32/lib" -g3
INC = -I"C:/MinGW/include" -I"C:/MinGW/x86_64-w64-mingw32/include" -I"C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include"
SRC_DIR:=src
OBJ_DIR:=obj
BIN_DIR:=bin
EXE:=$(BIN_DIR)/$(PROJECT)
SRC:=$(wildcard $(SRC_DIR)/*.c)
OBJ:=$(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
-include $(OBJ:.o=.d)
all: $(EXE)
.PHONY: all clean
$(EXE): $(OBJ) | $(BIN_DIR)
#echo ---------------------------Linking
$(CC) $(OBJ) -o $# $(LIBS)
$(OBJ_DIR)/%.o: $(SRC) | $(OBJ_DIR)
#echo ---------------------------Creating .o files
$(CC) -c $< -o $# $(CFLAGS)
$(OBJ_DIR) $(BIN_DIR):
#echo ---------------------------Creating Directory
mkdir $#
#echo ---------------------------Directory Created
clean:
#echo ---------------------------Clean started
rmdir /Q /S $(OBJ_DIR)
rmdir /Q /S $(BIN_DIR)
#echo ---------------------------Clean finished
I am learning to programming in C and i couldn't found nothing related with this and others errors with ncurses saying that curses.h didn't exist(i tried this both directives ncursesw/curses.h and curses.h). I dont know if OS matter but I'm running in windows. The main code is just a test code for this compilation:
#include <ncursesw/curses.h>
#include <stdlib.h>
int main()
{
int x=10;
initscr();
raw();
printw("%d",x);
getch();
endwin();
return 0;
}
I just reinstalled MinGw Posix and didn't merge the opt folder with include folder, probably I accidentally rewrited crtdefs.h the first time i installed MinGW.
Related
This is the error when I run make:
Undefined symbols for architecture arm64:
"\_add", referenced from:
\_main in a4-1-989722.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: \*\*\* \[a4-1\] Error 1
note (one of the functions in my module is add()
This is the makefile:
CC = gcc
CFLAGS = -Wall -Wextra -pedantic
TARGET = a4-1
DEP1 = myMath
all: $(TARGET)
debug: CFLAGS += -DDBUG
debug: $(TARGET)
&(TARGET): $(TARGET).c $(DEP1).o
$(CC) $(CFLAGS) $(DEP1).o -o $(TARGET) $(TARGET).c
$(DEP1).o: $(DEP1).c
$(CC) $(CFLAGS) -c $(DEP1).c
clean:
rm $(TARGET) *.o
This is the module .c file:
#include <stdio.h>
#include <stdlib.h>
int add(int x, int y)
{
return(x + y);
}
This is the module .h file:
int add(int, int);
#include "module.h"
in module.c
I am compiling a snmp agent application using net-snmp and compiling it correctly with this Makefile:
CC = gcc
SRC = $(shell find . -name '*.c')
OBJS = $(SRC:.c=.o)
TARGET = agent_daemon
CFLAGS = -I. `net-snmp-config --cflags`
# CFLAGS = -I. `net-snmp-config --cflags` `rapidjson`
BUILDLIBS = `net-snmp-config --libs`
BUILDAGENTLIBS = `net-snmp-config --agent-libs`
# shared library flags (assumes gcc)
DLFLAGS = -fPIC -shared
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) -o $(TARGET) $(OBJS) $(BUILDAGENTLIBS)
clean:
rm -Rf $(OBJS) $(TARGET)
Now I need to use the rapidjson library in one of the snmp agent's .c files.
rapidson is installed in /usr/include/rapidjson
In the .c file I have added the following include:
#include "rapidjson/filereadstream.h"
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
And the source code that is using rapidjson is this:
char readBuffer[65536];
FILE* fp = fopen("my_config_file.json", "r");
FileReadStream is(fp, readBuffer, sizeof(readBuffer));
Document doc;
doc.ParseStream(is);
char jsonKey[21];
fclose(fp);
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
doc.Accept(writer);
printf("JSON: %s\n", buffer.GetString());
In order to be able to compile the version of the SNMP agent that uses rapidjson I have changed in the previous Makefile the line:
CC = gcc
For :
CC = g++
However, when compiling it with the new Makefile, I get these errors:
readConfigFile.c:42:3: error: ‘FileReadStream’ was not declared in this scope
FileReadStream is(fp, readBuffer, sizeof(readBuffer));
^
readConfigFile.c:42:3: note: suggested alternative:
In file included from readConfigFile.c:17:0:
/usr/include/rapidjson/filereadstream.h:33:7: note: ‘rapidjson::FileReadStream’
class FileReadStream {
^
readConfigFile.c:44:3: error: ‘Document’ was not declared in this scope
Document doc;
^
readConfigFile.c:44:3: note: suggested alternative:
In file included from readConfigFile.c:18:0:
/usr/include/rapidjson/document.h:1889:34: note: ‘rapidjson::Document’
typedef GenericDocument<UTF8<> > Document;
^
readConfigFile.c:45:3: error: ‘doc’ was not declared in this scope
doc.ParseStream(is);
^
readConfigFile.c:45:19: error: ‘is’ was not declared in this scope
doc.ParseStream(is);
^
readConfigFile.c:50:3: error: ‘StringBuffer’ was not declared in this scope
StringBuffer buffer;
^
readConfigFile.c:50:3: note: suggested alternative:
In file included from /usr/include/rapidjson/writer.h:29:0,
from readConfigFile.c:19:
/usr/include/rapidjson/stringbuffer.h:69:38: note: ‘rapidjson::StringBuffer’
typedef GenericStringBuffer<UTF8<> > StringBuffer;
^
readConfigFile.c:51:3: error: ‘Writer’ was not declared in this scope
Writer<StringBuffer> writer(buffer);
^
readConfigFile.c:51:3: note: suggested alternative:
In file included from readConfigFile.c:19:0:
/usr/include/rapidjson/writer.h:56:7: note: ‘rapidjson::Writer’
class Writer {
^
readConfigFile.c:51:31: error: ‘buffer’ was not declared in this scope
Writer<StringBuffer> writer(buffer);
^
readConfigFile.c:51:37: error: ‘writer’ was not declared in this scope
Writer<StringBuffer> writer(buffer);
^
<builtin>: recipe for target 'readConfigFile.o' failed
make: *** [readConfigFile.o] Error 1
I have tried modifying the Makefile and adding "-I" option, like this:
$(TARGET): $(OBJS)
$(CC) -o $(TARGET) $(OBJS) $(BUILDAGENTLIBS) -I/usr/include/rapidjson
But I get the same errors.
I appreciate any help or suggestions.
I am in the process of converting my gmake build to cmake builds. The application builds fine with gmake, but I get the errors below when I use cmake.
Below are the gmake and cmake files.
parent Makefile
CC := gcc
CFLAGS := -g -w -m32
INC_DIR := ../includes
OBJ_DIR := ../objects
BIN_DIR := ../bin
child Makefile
include ../../Makefile
SHR_FX := ../$(OBJ_DIR)/shrfx.o
SHRXML := ../$(OBJ_DIR)/shrxml.o
TMP_BIN_DIR = ../$(BIN_DIR)
TMP_INC_DIR = ../$(INC_DIR)
EXECUTABLES := common flogmon
all: $(EXECUTABLES)
%: %.c OAhelper.c OAhelper.h $(SHR_FX) $(TMP_INC_DIR)
#-rm -f $# ## QUIET (#). CONTINUE IF FILE NOT FOUND (-)
$(CC) $(CFLAGS) -I $(TMP_INC_DIR) $(LDLIBPATHFLAGS) -o $# $#.c OAhelper.c $(SHR_FX)
#-chmod 0775 $# #SH(#),CONT(-). Allow others to do it.
mv $# $(TMP_BIN_DIR)
parent CMakeList.txt
cmake_minimum_required(VERSION 2.8.9)
project(program)
set(CMAKE_BUILD_TYPE Release)
set (EXECUTABLE_OUTPUT_PATH "/home/user/workspace/program")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -w -m32")
add_subdirectory(opaid/opaid_helper)
child CMakeList.txt
cmake_minimum_required(VERSION 2.8.9)
#Bring the headers
include_directories(../../includes)
set (PROJ_LIST "common;flogmon")
message ( STATUS "CFLAGS : " ${CMAKE_C_FLAGS})
foreach (PROJ ${PROJ_LIST})
project(${PROJ})
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath=${EXECUTABLE_OUTPUT_PATH}:${EXECUTABLE_OUTPUT_PATH}../RSA/cryptocme3001/library/lib")
add_executable(${PROJ} ${PROJ}.c OAhelper.c )
target_link_libraries(${PROJ} LINK_PUBLIC shrfx)
install(TARGETS ${PROJ} DESTINATION ${EXECUTABLE_OUTPUT_PATH})
endforeach()
Error
Building C object /CMakeFiles/common.dir/common.c.o
In file included from /usr/include/features.h:375:0,
from /usr/include/sys/poll.h:22,
from /usr/include/poll.h:1,
from /home/user/workspace/program/src/common.c:26:
/usr/include/sys/stat.h:503:1: error: conflicting types for ‘stat64’
__NTH (stat64 (const char *__path, struct stat64 *__statbuf))
^
In file included from
/home/user/workspace/program/src/../../includes/fxgen.h:205:0,
from /home/user/workspace/program/src/../../includes/fx.h:286,
from /home/user/workspace/program/src/common.c:39:
/usr/include/sys/stat.h:229:12: note: previous declaration of ‘stat64’
was here extern int stat64 (const char *__restrict __file,
If I look in /usr/include/sys/stat.h...
503
# if defined __USE_LARGEFILE64 \
&& (! defined __USE_FILE_OFFSET64 \
|| (defined __REDIRECT_NTH && defined __OPTIMIZE__))
__extern_inline int
__NTH (stat64 (const char *__path, struct stat64 *__statbuf))
{
return __xstat64 (_STAT_VER, __path, __statbuf);
}
229
#ifdef __USE_LARGEFILE64
extern int stat64 (const char *__restrict __file,
struct stat64 *__restrict __buf) __THROW __nonnull ((1, 2));
extern int fstat64 (int __fd, struct stat64 *__buf) __THROW __nonnull ((2));
#endif
Adding this to my CMAKEList.txt solved the problem:
STRING(REPLACE "-O3" "-O0" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
This question already has answers here:
Is it a good idea to typedef pointers?
(15 answers)
Closed 6 years ago.
I have this line in a header file:
typedef struct mystruct *mystruct;
And the corresponding struct definition in a .c file. Pretty standard practices.
I am getting this compilation error:
fatal error: typedef redefinition with different types ('struct mystruct *' vs mystruct')
This is using the Hexagon Tools Compiler (7.2.12) from Hexagon 3.0 SDK. It is officially QuIC LLVM Hexagon Clang version 7.2.12. Building for Snapdragon Flight. This should work as far as I know. It works with Ubuntu clang version 3.5.0-4ubuntu2~trusty2 (based on LLVM 3.5.0) for x86_64-pc-linux-gnu.
What is wrong here? Is this type of typedef a newer feature of C that is not implemented in the compiler, or rather are compiler differences like these common?
Edit: Actually struct is defined in a .c, not .cpp, file. Added the Makefile and make output showing compilation with Ubuntu clang, as well as the top of the header file with the troublesome typedef statment. A test is run at the end, and all 105 tests pass.
Edit2: See Jonathan Leffler's answer for cases where this works vs doesn't work.
ringbuf.h:
#include <stddef.h>
#include <sys/types.h>
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
typedef struct ringbuf_t *ringbuf_t;
Makefile:
CC=clang
CFLAGS=-O0 -g -Wall -Wpointer-arith -ftrapv -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error
# or, for gcc...
#CC=gcc
#CFLAGS=-O0 -g -Wall
LD=$(CC)
LDFLAGS=-g
test: ringbuf-test
./ringbuf-test
coverage: ringbuf-test-gcov
./ringbuf-test-gcov
gcov -o ringbuf-gcov.o ringbuf.c
valgrind: ringbuf-test
valgrind ./ringbuf-test
help:
#echo "Targets:"
#echo
#echo "test - build and run ringbuf unit tests."
#echo "coverage - use gcov to check test coverage of ringbuf.c."
#echo "valgrind - use valgrind to check for memory leaks."
#echo "clean - remove all targets."
#echo "help - this message."
ringbuf-test-gcov: ringbuf-test-gcov.o ringbuf-gcov.o
gcc -o ringbuf-test-gcov --coverage $^
ringbuf-test-gcov.o: ringbuf-test.c ringbuf.h
gcc -c $< -o $#
ringbuf-gcov.o: ringbuf.c ringbuf.h
gcc --coverage -c $< -o $#
ringbuf-test: ringbuf-test.o libringbuf.so
$(LD) -o ringbuf-test $(LDFLAGS) $^ -L$(MY_LIBS_PATH) -lringbuf
ringbuf-test.o: ringbuf-test.c ringbuf.h
$(CC) $(CFLAGS) -c $< -o $#
libringbuf.so: ringbuf.o
$(CC) -shared -o libringbuf.so ringbuf.o
cp ./libringbuf.so $(MY_LIBS_PATH)/
ringbuf.o: ringbuf.c ringbuf.h
$(CC) $(CFLAGS) -fPIC -c $< -o $#
cp ./ringbuf.h $(MY_INCLUDES_PATH)/
clean:
rm -f ringbuf-test ringbuf-test-gcov *.o *.so *.gcov *.gcda *.gcno
.PHONY: clean
make output:
clang -O0 -g -Wall -Wpointer-arith -ftrapv -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error -c ringbuf-test.c -o ringbuf-test.o
clang -O0 -g -Wall -Wpointer-arith -ftrapv -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error -fPIC -c ringbuf.c -o ringbuf.o
cp ./ringbuf.h /home/eric/Includes/
clang -shared -o libringbuf.so ringbuf.o
cp ./libringbuf.so /home/eric/Libs/
clang -o ringbuf-test -g ringbuf-test.o libringbuf.so -L/home/eric/Libs -lringbuf
./ringbuf-test
Edit3: This actually works fine with just the Hexagon-clang compiler. It is the compilation process of the larger program that this module exists in that is being problematic. I think that it is attempting to compile this code as C++.
Your code would be fine, in C and C++, if you did not try to Use typedef for a pointer type.
The header (hdr.h for instance) could/should contain:
typedef struct mystruct mystruct;
The source (hdr.cpp for instance) could contain:
#include "hdr.h"
struct mystruct
{
const char *a;
int b;
int c;
};
#include <iostream>
int main()
{
mystruct *ap = new mystruct;
ap->a = "collywobbles";
ap->b = 1;
ap->c = 2;
std::cout << "a: " << ap->a << ", b = " << ap->b << ", c = " << ap->c << "\n";
return 0;
}
This will compile in C++, even under stringent warnings. An equivalent C main() using <stdio.h> would work in C.
A Header file(stdint.h) is not included. I know a lot of code is following, but I have really no idea.
My Files:
gdt.c
/* We need 8 segments */
#include <stdint.h>
#include "gdt.h"
#define GDT_SIZE 8
uint32_t intr;
gdt_entry gdtable[GDT_SIZE];
include/gdt.h
#ifndef GDT_H
#define GDT_H
#include <stdint.h>
struct gdt_entry{
uint_16t limit;
uint_32t base :24;
uint_32t accessbyte :8;
uint_32t limit2 :4;
uint_32t flags2 :4;
uint_32t base2 :8;
}__attribute__((packed));
#endif
include/stdint.h
#ifndef STDINT_H
#define STDINT_H
typedef unsigned long long uint64_t;
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
typedef signed long long int64_t;
typedef signed int int32_t;
typedef signed short int16_t;
typedef signed char int8_t;
#endif
Makefile:
SRCS = $(shell find -name '*.[cS]')
OBJS = $(addsuffix .o,$(basename $(SRCS)))
CC = gcc
LD = ld
ASFLAGS = -m32
CFLAGS = -m32 -Wall -g -fno-stack-protector -I include
LDFLAGS = -melf_i386 -Tkernel.ld
kernel: $(OBJS)
$(LD) $(LDFLAGS) -o $# $^
%.o: %.c
$(CC) $(CFLAGS) -c -o $# $^
%.o: %.S
$(CC) $(ASFLAGS) -c -o $# $^
clean:
rm $(OBJS)
.PHONY: clean
kernel.ld
/* start should be executed first */
ENTRY(_start)
/*
* thats how the sections should be written in the .elf binary
*/
SECTIONS
{
/*
* the first section has a 1MB Offset for the grub bootloader
*/
. = 0x100000;
/*
* the multiboot header comes first
*/
.text : {
*(multiboot)
*(.text)
}
.data ALIGN(4096) : {
*(.data)
}
.rodata ALIGN(4096) : {
*(.rodata)
}
.bss ALIGN(4096) : {
*(.bss)
}
}
gcc output:
gcc -m32 -c -o start.o start.S
gcc -m32 -Wall -g -fno-stack-protector -I include -c -o gdt.o gdt.c
In file included from gdt.c:3:0:
include/gdt.h:5:2: error: unknown type name ‘uint_16t’
include/gdt.h:6:2: error: unknown type name ‘uint_32t’
include/gdt.h:7:2: error: unknown type name ‘uint_32t’
include/gdt.h:8:2: error: unknown type name ‘uint_32t’
include/gdt.h:9:2: error: unknown type name ‘uint_32t’
include/gdt.h:10:2: error: unknown type name ‘uint_32t’
gdt.c:7:1: error: unknown type name ‘gdt_entry’
make: *** [gdt.o] Error 1
I think you should use uint32_t instead of the non-standard uint_32t. It's at least the third variant I've come across, previously I've also seen u_int32_t.
There was another issue:
gdt_entry gdtable[GDT_SIZE]; should be struct gdt_entry gdtable[GDT_SIZE]