C Program Compile Error (with header file) - c

Here is my code of Header File.
Header File name 16f877a.h
its code get from this link
My File name led.c
#include "16f877a.h" //IC selection
#fuses XT, NOWDT, NOPROTECT, NOLVP
#use delay (clock =20000000) //clock 20MHz
void main(){
while(1){
output_B(0xff); //hex to binary output on port B
delay_us(500); // delay = 500 x clock period.
output_B(0x00);
delay_us(500);
}
}
those files are located in same folder
/home/company/Documents/CCPP/PIC/LedProject
I use UBUNTU 12.04.
with gcc I compiled a simple hello world program and its runs correctly.
here is my command history in terminal
mkdir -p PIC/LedProject
cd PIC/LedProject/
gedit led.c
gcc -Wall -W -Werror led.c -o LedProC
and here is my error.please help me to sort this issue
In file included from led.c:1:0:
16f877a.h:91:0: error: ignoring #pragma maxram [-Werror=unknown-pragmas]
16f877a.h:99:0: error: ignoring #pragma memmap INDF_ADDR [-Werror=unknown-pragmas]
16f877a.h:100:0: error: ignoring #pragma memmap TMR0_ADDR [-Werror=unknown-pragmas]
16f877a.h:101:0: error: ignoring #pragma memmap PCL_ADDR [-Werror=unknown-pragmas]
16f877a.h:102:0: error: ignoring #pragma memmap STATUS_ADDR [-Werror=unknown-pragmas]
16f877a.h:103:0: error: ignoring #pragma memmap FSR_ADDR [-Werror=unknown-pragmas]
16f877a.h:104:0: error: ignoring #pragma memmap PORTA_ADDR [-Werror=unknown-pragmas]
16f877a.h:105:0: error: ignoring #pragma memmap PORTB_ADDR [-Werror=unknown-pragmas]
16f877a.h:106:0: error: ignoring #pragma memmap PORTC_ADDR [-Werror=unknown-pragmas]
16f877a.h:107:0: error: ignoring #pragma memmap PORTD_ADDR [-Werror=unknown-pragmas]
16f877a.h:108:0: error: ignoring #pragma memmap PORTE_ADDR [-Werror=unknown-pragmas]
16f877a.h:109:0: error: ignoring #pragma memmap PCLATH_ADDR [-Werror=unknown-pragmas]
16f877a.h:110:0: error: ignoring #pragma memmap INTCON_ADDR [-Werror=unknown-pragmas]
16f877a.h:111:0: error: ignoring #pragma memmap PIR1_ADDR [-Werror=unknown-pragmas]
16f877a.h:112:0: error: ignoring #pragma memmap PIR2_ADDR [-Werror=unknown-pragmas]
16f877a.h:113:0: error: ignoring #pragma memmap TMR1L_ADDR [-Werror=unknown-pragmas]
16f877a.h:114:0: error: ignoring #pragma memmap TMR1H_ADDR [-Werror=unknown-pragmas]
16f877a.h:115:0: error: ignoring #pragma memmap T1CON_ADDR [-Werror=unknown-pragmas]
16f877a.h:116:0: error: ignoring #pragma memmap TMR2_ADDR [-Werror=unknown-pragmas]
16f877a.h:117:0: error: ignoring #pragma memmap T2CON_ADDR [-Werror=unknown-pragmas]
16f877a.h:118:0: error: ignoring #pragma memmap SSPBUF_ADDR [-Werror=unknown-pragmas]
16f877a.h:119:0: error: ignoring #pragma memmap SSPCON_ADDR [-Werror=unknown-pragmas]
16f877a.h:120:0: error: ignoring #pragma memmap CCPR1L_ADDR [-Werror=unknown-pragmas]
16f877a.h:121:0: error: ignoring #pragma memmap CCPR1H_ADDR [-Werror=unknown-pragmas]
16f877a.h:122:0: error: ignoring #pragma memmap CCP1CON_ADDR [-Werror=unknown-pragmas]
16f877a.h:123:0: error: ignoring #pragma memmap RCSTA_ADDR [-Werror=unknown-pragmas]
16f877a.h:124:0: error: ignoring #pragma memmap TXREG_ADDR [-Werror=unknown-pragmas]
16f877a.h:125:0: error: ignoring #pragma memmap RCREG_ADDR [-Werror=unknown-pragmas]
16f877a.h:126:0: error: ignoring #pragma memmap CCPR2L_ADDR [-Werror=unknown-pragmas]
16f877a.h:127:0: error: ignoring #pragma memmap CCPR2H_ADDR [-Werror=unknown-pragmas]
16f877a.h:128:0: error: ignoring #pragma memmap CCP2CON_ADDR [-Werror=unknown-pragmas]
16f877a.h:129:0: error: ignoring #pragma memmap ADRESH_ADDR [-Werror=unknown-pragmas]
16f877a.h:130:0: error: ignoring #pragma memmap ADCON0_ADDR [-Werror=unknown-pragmas]
16f877a.h:131:0: error: ignoring #pragma memmap OPTION_REG_ADDR [-Werror=unknown-pragmas]
16f877a.h:132:0: error: ignoring #pragma memmap TRISA_ADDR [-Werror=unknown-pragmas]
16f877a.h:133:0: error: ignoring #pragma memmap TRISB_ADDR [-Werror=unknown-pragmas]
16f877a.h:134:0: error: ignoring #pragma memmap TRISC_ADDR [-Werror=unknown-pragmas]
16f877a.h:135:0: error: ignoring #pragma memmap TRISD_ADDR [-Werror=unknown-pragmas]
16f877a.h:136:0: error: ignoring #pragma memmap TRISE_ADDR [-Werror=unknown-pragmas]
16f877a.h:137:0: error: ignoring #pragma memmap PIE1_ADDR [-Werror=unknown-pragmas]
16f877a.h:138:0: error: ignoring #pragma memmap PIE2_ADDR [-Werror=unknown-pragmas]
16f877a.h:139:0: error: ignoring #pragma memmap PCON_ADDR [-Werror=unknown-pragmas]
16f877a.h:140:0: error: ignoring #pragma memmap SSPCON2_ADDR [-Werror=unknown-pragmas]
16f877a.h:141:0: error: ignoring #pragma memmap PR2_ADDR [-Werror=unknown-pragmas]
16f877a.h:142:0: error: ignoring #pragma memmap SSPADD_ADDR [-Werror=unknown-pragmas]
16f877a.h:143:0: error: ignoring #pragma memmap SSPSTAT_ADDR [-Werror=unknown-pragmas]
16f877a.h:144:0: error: ignoring #pragma memmap TXSTA_ADDR [-Werror=unknown-pragmas]
16f877a.h:145:0: error: ignoring #pragma memmap SPBRG_ADDR [-Werror=unknown-pragmas]
16f877a.h:146:0: error: ignoring #pragma memmap ADRESL_ADDR [-Werror=unknown-pragmas]
16f877a.h:147:0: error: ignoring #pragma memmap ADCON1_ADDR [-Werror=unknown-pragmas]
16f877a.h:148:0: error: ignoring #pragma memmap EEDATA_ADDR [-Werror=unknown-pragmas]
16f877a.h:149:0: error: ignoring #pragma memmap EEADR_ADDR [-Werror=unknown-pragmas]
16f877a.h:150:0: error: ignoring #pragma memmap EEDATH_ADDR [-Werror=unknown-pragmas]
16f877a.h:151:0: error: ignoring #pragma memmap EEADRH_ADDR [-Werror=unknown-pragmas]
16f877a.h:152:0: error: ignoring #pragma memmap EECON1_ADDR [-Werror=unknown-pragmas]
16f877a.h:153:0: error: ignoring #pragma memmap EECON2_ADDR [-Werror=unknown-pragmas]
16f877a.h:206:1: error: unknown type name ‘data’
16f877a.h:206:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before numeric constant
16f877a.h:207:1: error: unknown type name ‘sfr’
16f877a.h:207:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before numeric constant
16f877a.h:208:1: error: unknown type name ‘data’
16f877a.h:208:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before numeric constant
16f877a.h:209:1: error: unknown type name ‘sfr’
16f877a.h:209:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before numeric constant
16f877a.h:267:1: error: unknown type name ‘sbit’
16f877a.h:267:1: error: expected declaration specifiers or ‘...’ before ‘(’ token
16f877a.h:268:1: error: unknown type name ‘sbit’
16f877a.h:485:1: error: expected declaration specifiers or ‘...’ before ‘(’ token
16f877a.h:486:1: error: unknown type name ‘sbit’
16f877a.h:486:1: error: expected declaration specifiers or ‘...’ before ‘(’ token
led.c:2:2: error: invalid preprocessing directive #fuses
led.c:3:2: error: invalid preprocessing directive #use
led.c:4:6: error: return type of ‘main’ is not ‘int’ [-Werror=main]
led.c: In function ‘main’:
led.c:6:3: error: implicit declaration of function ‘output_B’ [-Werror=implicit-function-declaration]
led.c:7:3: error: implicit declaration of function ‘delay_us’ [-Werror=implicit-function-declaration]
cc1: all warnings being treated as errors
bellvantage#BVPC00024:~/Documents/CCPP/PIC/LedProject$ mkdir -p PIC/LedProject
bellvantage#BVPC00024:~/Documents/CCPP/PIC/LedProject$ cd PIC/LedProject/
bellvantage#BVPC00024:~/Documents/CCPP/PIC/LedProject/PIC/LedProject$ gedit led.c
bellvantage#BVPC00024:~/Documents/CCPP/PIC/LedProject/PIC/LedProject$ gcc -Wall -W -Werror led.c -o LedProC
gcc: error: led.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.
I refer this blog for my circuit

You are using source code that is not strictly C but an extension that includes many preprocessor commands like
#fuses XT, NOWDT, NOPROTECT, NOLVP
#use delay (clock =20000000) //clock 20MHz
These are use to configure a PIC processor. The complier for this C like language has a built in understanding of functions like
delay_us()
The compliant C compiler (gcc) you used has no understand of fuse, delay_us , etc. and so declares a host of errors.
If you goal is to program a PIC - which I think it is, using this type of C, go to MicroChip, CCS, or elsewhere and get their PIC C compiler.
If you goal is to program with your gcc on your UBUNTU machine, do not use code designed for PICs.
BTW: There may exist cross-compilers for PIC that compile on your UBUNTU, but I am not aware.
Search the questions for gcc PIC cross-compiler and you may find it answered.

Related

Failed to compile bindsnoop eBPF c code outside of kernel tree

I'm trying to build a BPF program written in C into the bpf bytecode. The program C code was taken from https://github.com/iovisor/bcc/blob/master/tools/bindsnoop.py (I used C code from bpf_text with some customizations).
I didn't want to use bcc python tools, my purpose is to write both kernel and user space code in C, and I would like to build a kernel program outside of the kernel tree.
I use Ubuntu 20.10 and here is uname -a output:
Linux bb-VirtualBox 5.8.0-63-generic #71-Ubuntu SMP Tue Jul 13 15:59:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Linux headers are installed, but for some reason I have two directories containing linux headers for 5.8.0-63:
/usr/src/linux-headers-5.8.0-63
and
/usr/src/linux-headers-5.8.0-63-generic
I used this post to create a makefile for my program: https://blogs.oracle.com/linux/post/bpf-in-depth-building-bpf-programs
so the makefile looks like below:
OBJS = kprobe_bindsnoop_kern.o
LLC ?= llc
CLANG ?= clang
INC_FLAGS = -nostdinc -isystem `$(CLANG) -print-file-name=include`
EXTRA_CFLAGS ?= -O2 -emit-llvm
linuxhdrsgen ?= /usr/src/linux-headers-5.8.0-63-generic
LINUXINCLUDE = -I$(linuxhdrsgen)/arch/x86/include \
-I$(linuxhdrsgen)/arch/x86/include/generated/uapi \
-I$(linuxhdrsgen)/arch/x86/include/generated \
-I$(linuxhdrsgen)/arch/x86/include/uapi \
-I$(linuxhdrsgen)/arch/x86/include/generated/uapi \
-I$(linuxhdrsgen)/include/uapi \
-I$(linuxhdrsgen)/include/generated/uapi \
-I$(linuxhdrsgen)/include \
-include ${linuxhdrsgen}/include/linux/kconfig.h
all: $(OBJS)
.PHONY: clean
clean:
rm -f $(OBJS)
INC_FLAGS = -nostdinc -isystem `$(CLANG) -print-file-name=include`
$(OBJS): %.o:%.c
$(CLANG) $(INC_FLAGS) \
-D__KERNEL__ -D__ASM_SYSREG_H \
-Wno-unused-value -Wno-pointer-sign \
-Wno-compare-distinct-pointer-types \
-Wno-gnu-variable-sized-type-not-at-end \
-Wno-address-of-packed-member -Wno-tautological-compare \
-Wno-unknown-warning-option \
-I../include $(LINUXINCLUDE) \
$(EXTRA_CFLAGS) -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $#
And kprobe_bindsnoop_kern.c starts from the following set of include files:
#include <uapi/linux/ptrace.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-compare"
#include <net/sock.h>
#pragma clang diagnostic pop
#include <net/inet_sock.h>
#include <net/net_namespace.h>
#include <bcc/proto.h>
Below you can see the compilation output:
clang -nostdinc -isystem `clang -print-file-name=include` \
-D__KERNEL__ -D__ASM_SYSREG_H \
-Wno-unused-value -Wno-pointer-sign \
-Wno-compare-distinct-pointer-types \
-Wno-gnu-variable-sized-type-not-at-end \
-Wno-address-of-packed-member -Wno-tautological-compare \
-Wno-unknown-warning-option \
-I../include -I/usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/ -I/usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/generated/uapi -I/usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/generated/ -I/usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/uapi -I/usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/generated/uapi -I/usr/src/linux-headers-5.8.0-63-generic/include/uapi -I/usr/src/linux-headers-5.8.0-63-generic/include/generated/uapi -I/usr/src/linux-headers-5.8.0-63-generic/include -include /usr/src/linux-headers-5.8.0-63-generic/include/linux/kconfig.h \
-O2 -emit-llvm -c kprobe_bindsnoop_kern.c -o -| llc -march=bpf -filetype=obj -o kprobe_bindsnoop_kern.o
In file included from kprobe_bindsnoop_kern.c:22:
In file included from /usr/src/linux-headers-5.8.0-63-generic/include/uapi/linux/ptrace.h:143:
In file included from /usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/asm/ptrace.h:5:
In file included from /usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/asm/segment.h:6:
/usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/asm/alternative.h:59:2: error: unknown type name 's32'
s32 instr_offset; /* original instruction */
^
/usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/asm/alternative.h:60:2: error: unknown type name 's32'
s32 repl_offset; /* offset to replacement instruction */
^
/usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/asm/alternative.h:61:2: error: unknown type name 'u16'
u16 cpuid; /* cpuid bit set for replacement */
^
/usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/asm/alternative.h:62:2: error: unknown type name 'u8'
u8 instrlen; /* length of original instruction */
^
/usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/asm/alternative.h:63:2: error: unknown type name 'u8'
u8 replacementlen; /* length of new instruction */
^
/usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/asm/alternative.h:64:2: error: unknown type name 'u8'
u8 padlen; /* length of build-time padding */
^
/usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/asm/alternative.h:85:8: error: unknown type name 'bool'
extern bool skip_smp_alternatives;
^
In file included from kprobe_bindsnoop_kern.c:22:
In file included from /usr/src/linux-headers-5.8.0-63-generic/include/uapi/linux/ptrace.h:143:
In file included from /usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/asm/ptrace.h:5:
In file included from /usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/asm/segment.h:169:
In file included from /usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/asm/cache.h:5:
In file included from /usr/src/linux-headers-5.8.0-63-generic/include/linux/linkage.h:7:
In file included from /usr/src/linux-headers-5.8.0-63-generic/include/linux/export.h:43:
In file included from /usr/src/linux-headers-5.8.0-63-generic/include/linux/compiler.h:266:
/usr/src/linux-headers-5.8.0-63-generic/include/linux/kasan-checks.h:16:15: error: unknown type name 'bool'
static inline bool __kasan_check_read(const volatile void *p, unsigned int size)
^
/usr/src/linux-headers-5.8.0-63-generic/include/linux/kasan-checks.h:18:9: error: use of undeclared identifier 'true'
return true;
^
/usr/src/linux-headers-5.8.0-63-generic/include/linux/kasan-checks.h:20:15: error: unknown type name 'bool'
static inline bool __kasan_check_write(const volatile void *p, unsigned int size)
^
/usr/src/linux-headers-5.8.0-63-generic/include/linux/kasan-checks.h:22:9: error: use of undeclared identifier 'true'
return true;
^
/usr/src/linux-headers-5.8.0-63-generic/include/linux/kasan-checks.h:34:15: error: unknown type name 'bool'
static inline bool kasan_check_read(const volatile void *p, unsigned int size)
^
/usr/src/linux-headers-5.8.0-63-generic/include/linux/kasan-checks.h:36:9: error: use of undeclared identifier 'true'
return true;
^
/usr/src/linux-headers-5.8.0-63-generic/include/linux/kasan-checks.h:38:15: error: unknown type name 'bool'
static inline bool kasan_check_write(const volatile void *p, unsigned int size)
^
/usr/src/linux-headers-5.8.0-63-generic/include/linux/kasan-checks.h:40:9: error: use of undeclared identifier 'true'
return true;
^
In file included from kprobe_bindsnoop_kern.c:22:
In file included from /usr/src/linux-headers-5.8.0-63-generic/include/uapi/linux/ptrace.h:143:
In file included from /usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/asm/ptrace.h:5:
In file included from /usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/asm/segment.h:169:
In file included from /usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/asm/cache.h:5:
In file included from /usr/src/linux-headers-5.8.0-63-generic/include/linux/linkage.h:7:
In file included from /usr/src/linux-headers-5.8.0-63-generic/include/linux/export.h:43:
In file included from /usr/src/linux-headers-5.8.0-63-generic/include/linux/compiler.h:267:
/usr/src/linux-headers-5.8.0-63-generic/include/linux/kcsan-checks.h:148:67: error: unknown type name 'size_t'
static inline void __kcsan_check_access(const volatile void *ptr, size_t size,
^
/usr/src/linux-headers-5.8.0-63-generic/include/linux/kcsan-checks.h:164:53: error: unknown type name 'size_t'
kcsan_begin_scoped_access(const volatile void *ptr, size_t size, int type,
^
/usr/src/linux-headers-5.8.0-63-generic/include/linux/kcsan-checks.h:184:65: error: unknown type name 'size_t'
static inline void kcsan_check_access(const volatile void *ptr, size_t size,
^
In file included from kprobe_bindsnoop_kern.c:22:
In file included from /usr/src/linux-headers-5.8.0-63-generic/include/uapi/linux/ptrace.h:143:
In file included from /usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/asm/ptrace.h:6:
In file included from /usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/asm/page_types.h:7:
In file included from /usr/src/linux-headers-5.8.0-63-generic/include/linux/mem_encrypt.h:17:
In file included from /usr/src/linux-headers-5.8.0-63-generic/arch/x86/include/asm/mem_encrypt.h:15:
/usr/src/linux-headers-5.8.0-63-generic/include/linux/init.h:155:8: error: unknown type name 'bool'
extern bool rodata_enabled;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
I tried to add
#include <linux/types.h> or
#include <asm/types.h>
but it doesn't help.
I checked many posts, like this
Error compiling eBPF C code out of kernel tree
and this
how to build BPF program out of the kernel tree
but still failed to get answer.
What am I missing?
Any help will be greatly appreciated ))
Thanks to everyone who tried to help me!
Finally the issue was sooooo simple - just needed to change an order of the include directories specified in the makefile.
Just moved "-I$(linuxhdrsgen)/include" to be the first in the list and it solved the issue.
Meaning, now the list of include dirs looks as follows:
LINUXINCLUDE = -I$(linuxhdrsgen)/include
-I$(linuxhdrsgen)/arch/x86/include
-I$(linuxhdrsgen)/arch/x86/include/generated/uapi
-I$(linuxhdrsgen)/arch/x86/include/generated
-I$(linuxhdrsgen)/arch/x86/include/uapi
-I$(linuxhdrsgen)/arch/x86/include/generated/uapi
-I$(linuxhdrsgen)/include/uapi
-I$(linuxhdrsgen)/include/generated/uapi
-include ${linuxhdrsgen}/include/linux/kconfig.h

compilation error for avx512, is it a GCC issue?

I am trying to compile the following code with AVX512 intrinsic, but gives me the compile error.
#include <immintrin.h>
static inline __attribute__((always_inline)) void
mov64(uint8_t *dst, const uint8_t *src)
{
__m512i zmm0;
zmm0 = _mm512_load_si512((const void *)src);
_mm512_store_si512((void *)dst, zmm0);
}
The compilation error:
gcc -D_GNU_SOURCE -DINFO_LOG_DEBUG --std=c99 -march=native -O3 -DNDEBUG -m64 -mtune=native -Werror -Wall -Wundef -Wpointer-arith -Wstrict-prototypes -Wnested-externs -fomit-frame-pointer -DTRANSPORT_CONFIG_OPT_HDR='<ci/internal/transport_config_opt_extra.h>' -c src/main.c -o obj/main.o
src/main.c: In function ‘mov64’:
src/main.c:15:9: error: unknown type name ‘__m512i’
__m512i zmm0;
^
src/main.c:17:9: error: implicit declaration of function ‘_mm512_load_si512’ [-Werror=implicit-function-declaration]
zmm0 = _mm512_load_si512((const void *)src);
^
src/main.c:17:9: error: nested extern declaration of ‘_mm512_load_si512’ [-Werror=nested-externs]
src/main.c:18:9: error: implicit declaration of function ‘_mm512_store_si512’ [-Werror=implicit-function-declaration]
_mm512_store_si512((void *)dst, zmm0);
^
src/main.c:18:9: error: nested extern declaration of ‘_mm512_store_si512’ [-Werror=nested-externs]
cc1: all warnings being treated as errors
In addition, if I add -march=native,avx512f or -mavx512f or -march=skylake-avx512, it gives the following error:
src/main.c:1:0: error: bad value (skylake-avx512) for -march= switch
My GCC version is 4.8.5 20150623 and CPU is "Intel(R) Xeon(R) Gold 6154". What should I do to overcome this problem? Thanks in advance..
GCC 4.8 does not support any of the AVX-512 variants. If this is the system compiler from Red Hat Enterprise Linux 7, you can use a new GCC version from Red Hat Developer Toolset, which provides support for later CPU features. (DTS is also available for CentOS.)

How should I compile this old code with cc

I'm trying to compile source code, that from 2001, in Ubuntu 18.04.2 LTS. But, I got the errors below and actually don't know how I have to change the compiling code. Can you help me for compiling this code?
Suggested compilation part from the program
SUGGESTED COMPILATION COMMAND LINE (FOR A DEC-ALPHA CC-COMPILER):
cc -lm -fast -tune host -arch host -assume whole_program \
-o mol_volume mol_volume.c
When I tried this code, errors;
cc: error: host: No such file or directory
cc: error: host: No such file or directory
cc: error: whole_program: No such file or directory
cc: error: unrecognized command line option ‘-fast’; did you mean ‘-Ofast’?
cc: error: unrecognized command line option ‘-tune’; did you mean ‘-mtune=’?
cc: error: unrecognized command line option ‘-arch’; did you mean ‘-march=’?
cc: error: unrecognized command line option ‘-assume’; did you mean ‘-msse’?
Then, I changed -fast, -tune, -arch, -assume flags with -Ofast, -mtune=native, -march=native, -msse then add the path the for the directory part of the errors.
cc -lm -Ofast -mtune=native -march=native -msse /mypath/ -o mol_volume mol_volume.c
Then, I got that error;
mol_volume.c: In function ‘main’:
mol_volume.c:235:10: warning: implicit declaration of function ‘gets’; did you mean ‘fgets’? [-Wimplicit-function-declaration]
while( gets(s) ) {
^~~~
fgets
mol_volume.c:311:26: warning: format ‘%i’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat=]
printf("WARNING: the %i-th atom of the pdb file %s has an unknown chemical type %s.\n",
~^
%li
i+1, pdb_name, atom_type);
~~~
/usr/bin/ld: cannot find .: File format not recognized
collect2: error: ld returned 1 exit status
You can access the source code via this link;
Source Code
My PC info:
Operation System: Ubuntu 18.04.2 LTS
Kernel ver.: 4.15.0-50-generic
GCC ver.: 7.4.0
gets was removed in C11. Compile with gcc -o mol_volume -Wall -std=c99 -mtune=native -O3 mol_volume.c -lm.
It will work but you should fix the code to remove all the warnings.

Cannot place kernel's prototype in header

io.cuh:
#ifndef IO_CUH
#define IO_CUH
#include <cuda.h>
typedef struct{
unsigned width;
unsigned height;
unsigned char *image; //RGBA
}rgb_image;
__global__ void transformToGrayKernel(rgb_image *img);
void decodeTwoSteps(const char* filename, rgb_image *img);
void encodeOneStep(const char* filename, rgb_image *img);
void processImage(const char *filename, rgb_image *img);
#endif // IO_CUH
I'm trying to compile simple program using the following makefile:
lodepng.o: lodepng.h
cc -c lodepng.c -o lodepng.o
io.o: io.cuh lodepng.o
nvcc -c io.cu -o io.o
main: io.o
nvcc main.c io.o -o main
'main.c' uses one function from io.cu, which is dependent on lodepng.c.
After some minor warnings that reference to the code, I got the following error:
nvcc main.c io.o -o main nvcc warning : The 'compute_10' and 'sm_10'
architectures are deprecated, and may be removed in a future release.
In file included from main.c:1:0: io.cuh:12:12: error: expected ‘=’,
‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘void’ global void
transformToGrayKernel(rgb_image *img);
^ makefile:6: recipe for target 'main' failed make: *** [main] Error 1
The error is caused by the key word __global__, not your kernel's prototype.
That's because the compiler nvcc will interpret its input file, and choose the corresponding rule to compile it. Although you use the nvcc to compile the "main.c", but it will be treated as a C source file, not a CUDA source code. So the compiler can not recognize the CUDA key word __global__ when it compile the file "main.c".
You can change the file type from "main.c" to "main.cu", and it will be treated as a CUDA source code. Then the compiler can recognize the key word __global__.

How to compile C version of vtd-xml under linux (32 bit)

I've downloaded ximpleware_2.11_c.zip (C version of vtd-xml), when I
have tried to compile it under linux I've the following error messages:
In file included from vtdNav.c:19:
vtdNav.h:82: error: expected declaration specifiers or ‘...’ before ‘FILE’
vtdNav.h:506: error: expected declaration specifiers or ‘...’ before ‘FILE’
vtdNav.h: In function ‘writeIndex_VTDNav’:
vtdNav.c: At top level:
vtdNav.c:3410: error: conflicting types for ‘writeIndex_VTDNav’
vtdNav.h:347: error: previous declaration of ‘writeIndex_VTDNav’ was here
vtdNav.c: In function ‘dumpXML’:
vtdNav.c:3554: error: too many arguments to function ‘dumpXML2’
vtdNav.c: At top level:
vtdNav.c:3562: error: conflicting types for ‘dumpXML2’
vtdNav.h:362: error: previous declaration of ‘dumpXML2’ was here
In file included from vtdNav.c:19:
vtdNav.h:82: error: expected declaration specifiers or ‘...’ before ‘FILE’
vtdNav.h:506: error: expected declaration specifiers or ‘...’ before ‘FILE’
vtdNav.h: In function ‘writeIndex_VTDNav’:
vtdNav.h:507: error: ‘f’ undeclared (first use in this function)
vtdNav.h:507: error: (Each undeclared identifier is reported only once
vtdNav.h:507: error: for each function it appears in.)
vtdNav.h:507: error: too many arguments to function
‘vn->__writeIndex_VTDNav’
vtdNav.h: At top level:
vtdNav.h:675: error: expected declaration specifiers or ‘...’ before ‘FILE’
vtdNav.h:695: error: expected declaration specifiers or ‘...’ before ‘FILE’
vtdNav.c: In function ‘_writeIndex2_VTDNav’:
vtdNav.c:3751: error: too many arguments to function ‘writeIndex_VTDNav’
vtdNav.c: In function ‘dumpXML’:
vtdNav.c:3874: error: too many arguments to function ‘dumpXML2’
vtdNav.c: At top level:
vtdNav.c:3882: error: conflicting types for ‘dumpXML2’
vtdNav.h:695: error: previous declaration of ‘dumpXML2’ was here
make: *** [vtdNav.o] Error 1
How can I build it under linux ?
Thanks for your response.
I've put
#include <stdio.h>
in :
vtdNav.h and in transcoder.h
and now it compile.
I'm sorry to have put a post to ask how to compile the examples. I have compiled them by modifying the makefile already present in ximpleware_2.11_c and in this way works:
CC=gcc
CFLAGS= -c -O3 -Wall -Winline -fgnu89-inline -fomit-frame-pointer-fforce-addr -frerun-cse-after-loop -fexpensive-optimizations -fregmove -frerun-loop-opt -fmerge-all-constants -fno-branch-count-reg -funroll-loops -fpeephole -march=core2-falign-functions -falign-loops -falign-jumps -freorder-blocks -freorder-functions-fprefetch-loop-arrays -funswitch-loops -fbranch-target-load-optimize2 -fvpt --paraminline-unit-growth=300 --param max-inline-recursive-depth=2 --param large-function-growth=600
CFLAGS2 = -c -ggdb
LDFLAGS = -O3 -fomit-frame-pointer -fforce-addr -frerun-cse-after-loop-fexpensive-optimizations -fregmove -frerun-loop-opt -march=core2 -lm
LDFLAGS2 = -ggdb
all : hello_world
hello_world: hello_world.o ../../arrayList.o ../../fastIntBuffer.o ../../fastLongBuffer.o ../../contextBuffer.o ../../vtdNav.o ../../vtdGen.o ../../autoPilot.o ../../XMLChar.o ../../helper.o ../../lex.yy.o ../../l8.tab.o ../../literalExpr.o ../../numberExpr.o ../../pathExpr.o ../../filterExpr.o ../../binaryExpr.o ../../unaryExpr.o ../../funcExpr.o ../../locationPathExpr.o ../../intHash.o ../../unionExpr.o ../../decoder.o ../../XMLModifier.o ../../nodeRecorder.o ../../indexHandler.o ../../bookMark.o ../../elementFragmentNs.o ../../transcoder.o ../../textIter.o ../../variableExpr.o ../../cachedExpr.o
clean:
-rm *.o
hello_world.o : hello_world.c
${CC} ${CFLAGS} hello_world.c

Resources