This is cross compile issue.
I crated xxxx.proto and generated C code by using protobuf-c project. It was compiled successfully on x86 linux.
But when I cross compiled it for MIPS, then it made compile error. I compiled protobuf, protobuf-c by using buildroot. And toolchain is sorcery tools.
The source code is like below.
#include <string.h>
#include "egmessage.pb-c.h" //header file that protobuf-c generated. I never touched it.
int main (void)
{
printf("Hello, world.");
return 0;
}
I tried to compile this code by using command below.
mips-linux-gnu-gcc egmessage.pb-c.c test.c -o extest -I/home/vagrant/tools/buildroot-2014.11/output/staging/usr/include -lprotobuf-c
Then I got the compile error like below.
In file included from test.c:6:0:
egmessage.pb-c.h:20:1: error: expected '=', ',', ';', 'asm' or '__attribute__' b
efore 'typedef'
typedef struct _ControlMessage ControlMessage;
^
egmessage.pb-c.h:35:23: error: unknown type name 'ControlMessage'
(ControlMessage *message);
^
egmessage.pb-c.h:37:22: error: unknown type name 'ControlMessage'
(const ControlMessage *message);
^
egmessage.pb-c.h:39:22: error: unknown type name 'ControlMessage'
(const ControlMessage *message,
^
egmessage.pb-c.h:42:22: error: unknown type name 'ControlMessage'
(const ControlMessage *message,
^
egmessage.pb-c.h:44:1: error: unknown type name 'ControlMessage'
ControlMessage *
^
egmessage.pb-c.h:50:23: error: unknown type name 'ControlMessage'
(ControlMessage *message,
^
egmessage.pb-c.h:54:18: error: unknown type name 'ControlMessage'
(const ControlMessage *message,
^
test.c:8:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
int main (void)
^
Error message said it want to use several symbol. Have you the experience like that?
I found the reason. I used protobuf I compiled manually. That version is different from buildroot's protobuf version. I applied buildroot's protobuf and compiled proto file again. Then it worked.
Related
I am trying to use readline in my Zig project.
I managed to make the linker find it by adding this to the build file:
exe.linkLibC();
exe.addIncludeDir("/usr/local/opt/readline/include");
exe.addLibPath("/usr/local/opt/readline/lib");
Even though it finds readline definitions it seems it doesn't "see" the C lib...
Error:
▶ zig build
./src/main.zig:1:18: error: C import failed
const readline = #cImport({
^
/usr/local/opt/readline/include/readline/rltypedefs.h:71:36: note: unknown type name 'FILE'
typedef int rl_getc_func_t PARAMS((FILE *));
^
/usr/local/opt/readline/include/readline/readline.h:448:28: note: unknown type name 'FILE'
extern int rl_getc PARAMS((FILE *));
^
/usr/local/opt/readline/include/readline/readline.h:578:8: note: unknown type name 'FILE'
extern FILE *rl_instream;
^
/usr/local/opt/readline/include/readline/readline.h:579:8: note: unknown type name 'FILE'
extern FILE *rl_outstream;
^
/usr/local/opt/readline/include/readline/readline.h:937:3: note: unknown type name 'FILE'
FILE *inf;
^
/usr/local/opt/readline/include/readline/readline.h:938:3: note: unknown type name 'FILE'
FILE *outf;
^
zig-lua...The following command exited with error code 1:
How can I make it work?
It seems that the problem was not in the build file but in the cImport.
I was doing this:
const readline = #cImport({
#cInclude("readline/readline.h");
});
As the error message was complaining about stuff from C's stdio.h, I added that too:
const readline = #cImport({
#cInclude("stdio.h");
#cInclude("readline/readline.h");
});
And now the Zig build works.
https://github.com/noyesno/awka
For the above repo, I got the following error when I try to compile it on macOS (gcc is just clang). I have no idea how to fix the problem according to the error message. It compiles fine on Linux.
I also tried the real gcc from Homebrew to compile the package. It also show the same error. How can I fix this problem on macOS?
$ ./configure
$ make
...
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\" -c -o print.o print.c
print.c:52:11: error: expected parameter declarator
int PROTO(sprintf, (char *, const char *,...)) ;
^
print.c:52:11: error: expected ')'
print.c:52:11: note: to match this '('
print.c:52:11: error: conflicting types for '__builtin___sprintf_chk'
int PROTO(sprintf, (char *, const char *,...)) ;
^
print.c:52:11: note: '__builtin___sprintf_chk' is a builtin with type 'int (char *, int, unsigned long, const char *, ...)'
3 errors generated.
make[1]: *** [<builtin>: print.o] Error 1
make[1]: Leaving directory '/private/tmp/awka/awka'
make: *** [Makefile:48: awka_exe] Error 2
I'm not going to spend ages on this, but it looks as though configure is gripping stdio.h looking for sprintf. It is unable to find it in the header, and so it adds the #define:
NO_SPRINTF_IN_STDIO
which it sets to 1, and uses it to add its own prototype for sprintf. Unfortunately, this appears to be a macro in this case, which replaces sprintf with '__builtin___sprintf_chk' instead (which has additional string length checks by the looks of it).
Possible solutions:
Comment out the line in print.c, and make sure stdio.h is included somewhere.
After running configure, search for where it defines NO_SPRINTF_IN_STDIO and set that var to 1?
Fix the configure to so a more rigorous test?
I'm running Cygwin on top of Windows 7. I'm having trouble trying to install the checkinstall utility from source, and the culprit appears to be gcc.
When I run /.configure, I get the error:
-bash: ./configure: No such file or directory
So I continue with make, and get output that fails with lots of errors, presumably caused by gcc. The output can be seen in its entirety here, but below are the first and last few lines of it.
$ make
for file in locale/checkinstall-*.po ; do \
case ${file} in \
locale/checkinstall-template.po) ;; \
*) \
out=`echo $file | sed -s 's/po/mo/'` ; \
msgfmt -o ${out} ${file} ; \
if [ $? != 0 ] ; then \
exit 1 ; \
fi ; \
;; \
esac ; \
done
make -C installwatch
make[1]: Entering directory '/cygdrive/b/Users/Me/Desktop/checkinstall-1.6.2/installwatch'
gcc -Wall -c -D_GNU_SOURCE -DPIC -fPIC -D_REENTRANT -DVERSION=\"0.7.0beta7\" installwatch.c
In file included from /usr/local/include/sys/param.h:33:0,
from installwatch.c:31:
/usr/local/include/sys/types.h:10:2: error: #error Only Win32 target is supported!
#error Only Win32 target is supported!
^~~~~
In file included from /usr/local/include/sys/param.h:33:0,
from installwatch.c:31:
/usr/local/include/sys/types.h:90:3: error: unknown type name ‘time_t’
time_t tv_sec; /* Seconds */
^~~~~~
In file included from installwatch.c:33:0:
/usr/local/include/sys/stat.h:10:2: error: #error Only Win32 target is supported!
#error Only Win32 target is supported!
^~~~~
In file included from /usr/local/include/sys/stat.h:14:0,
from installwatch.c:33:
/usr/local/include/io.h:199:28: error: expected ‘,’ or ‘;’ before ‘_findfirst32’
_CRTIMP intptr_t __cdecl _findfirst32(const char *_Filename,struct _finddata32_t *_FindData);
^~~~~~~~~~~~
...
installwatch.c: In function ‘fopen’:
installwatch.c:2560:51: error: expected ‘)’ before ‘result’
logg("%" PRIdPTR "\tfopen\t%s\t#%s\n",(intptr_t)result,
^~~~~~
installwatch.c:2560:8: warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat=]
logg("%" PRIdPTR "\tfopen\t%s\t#%s\n",(intptr_t)result,
^~~
installwatch.c:2560:8: warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat=]
installwatch.c:2575:51: error: expected ‘)’ before ‘result’
logg("%" PRIdPTR "\tfopen\t%s\t#%s\n",(intptr_t)result,
^~~~~~
installwatch.c:2575:8: warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat=]
logg("%" PRIdPTR "\tfopen\t%s\t#%s\n",(intptr_t)result,
^~~
installwatch.c:2575:8: warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat=]
installwatch.c: At top level:
installwatch.c:2600:7: error: conflicting types for ‘getcwd’
char *getcwd(char *buffer,size_t size) {
^~~~~~
In file included from /usr/local/include/sys/stat.h:14:0,
from installwatch.c:33:
/usr/local/include/io.h:279:17: note: previous declaration of ‘getcwd’ was here
char *__cdecl getcwd (char *, int) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
^~~~~~
installwatch.c:2664:30: error: unknown type name ‘uid_t’
int lchown(const char *path, uid_t owner, gid_t group) {
^~~~~
installwatch.c:2664:43: error: unknown type name ‘gid_t’
int lchown(const char *path, uid_t owner, gid_t group) {
^~~~~
installwatch.c:2749:5: error: conflicting types for ‘mkdir’
int mkdir(const char *pathname, mode_t mode) {
^~~~~
In file included from /usr/local/include/sys/stat.h:14:0,
from installwatch.c:33:
/usr/local/include/io.h:280:15: note: previous declaration of ‘mkdir’ was here
int __cdecl mkdir (const char *) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
^~~~~
installwatch.c:2983:7: error: conflicting types for ‘realpath’
char *realpath(const char *file_name,char *resolved_name) {
^~~~~~~~
installwatch.c:556:6: note: previous implicit declaration of ‘realpath’ was here
if(!realpath(path,resolved_path)) {
^~~~~~~~
installwatch.c:3309:5: error: conflicting types for ‘utime’
int utime (const char *pathname, const struct utimbuf *newtimes) {
^~~~~
In file included from /usr/local/include/utime.h:6:0,
from installwatch.c:47:
/usr/local/include/sys/utime.h:115:26: note: previous definition of ‘utime’ was here
__CRT_INLINE int __cdecl utime(const char *_Filename,struct utimbuf *_Utimbuf) {
^~~~~
installwatch.c: In function ‘true_stat’:
installwatch.c:153:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
installwatch.c: In function ‘true_lstat’:
installwatch.c:161:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
installwatch.c: In function ‘true_mknod’:
installwatch.c:157:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
In file included from installwatch.c:35:0:
installwatch.c: In function ‘open’:
installwatch.c:2842:20: warning: ‘mode_t {aka short unsigned int}’ is promoted to ‘int’ when passed through ‘...’
mode = va_arg(ap, mode_t);
^
installwatch.c:2842:20: note: (so you should pass ‘int’ not ‘mode_t {aka short unsigned int}’ to ‘va_arg’)
installwatch.c:2842:20: note: if this code is reached, the program will abort
At top level:
installwatch.c:1040:12: warning: ‘__instw_printdirent64’ defined but not used [-Wunused-function]
static int __instw_printdirent64(struct dirent64 *entry) {
^~~~~~~~~~~~~~~~~~~~~
make[1]: *** [Makefile:22: installwatch.o] Error 1
make[1]: Leaving directory '/cygdrive/b/Users/Me/Desktop/checkinstall-1.6.2/installwatch'
make: *** [Makefile:11: all] Error 2
I'm sorry in advance if I'm going about this the wrong way, but I'm completely out of my depth with this code and the errors being thrown. I've tried using the Cygwin installer to reinstall gcc_core and other gcc packages several times to no effect.
I was in the process of using this guide to compile the latest version of gcc from source before I ran into fatal errors with that too, and decided to start from the beginning and determine whether the problem can be solved without adding yet more bloat to my Cygwin installation. Thanks in advance, it's much appreciated.
The checkinstall app does not appear to be configured to run on cygwin. It is configured for several specific Linux distribution families, and has a generic source release.
I have downloaded and unpacked the checkinstall-1.6.2.tar.gz file; it expands into the checkinstall-1.6.2 directory. There you find the checkinstall shell script. I don't have the time to wade through several thousand lines of shell code. It appears to require you build and install the installwatch program, which I guess will register a file change handler in order to identify all new and changed files and directories. I suspect that handler would need to change to work properly in cygwin. You might have success posting to one of the Cygwin mailing lists.
HTH
Doug
I've been trying to compile XZ Utils using MinGW-w64 and when trying to run make after ./configureing, I get the error that sigset_t is unknown.
The XZ Utils version is 5.2.3, and my MinGW-w64 is x86_64-7.2.0-posix-seh-rt_v5-rv1.
In file included from common/common.h:17:0,
from common/common.c:13:
../../src/common/mythread.h:138:33: error: unknown type name 'sigset_t'
mythread_sigmask(int how, const sigset_t *restrict set,
^~~~~~~~
../../src/common/mythread.h:139:3: error: unknown type name 'sigset_t'; did you mean '_sigset_t'?
sigset_t *restrict oset)
^~~~~~~~
_sigset_t
../../src/common/mythread.h: In function 'mythread_create':
../../src/common/mythread.h:158:2: error: unknown type name 'sigset_t'; did you mean '_sigset_t'?
sigset_t old;
^~~~~~~~
_sigset_t
../../src/common/mythread.h:159:2: error: unknown type name 'sigset_t'; did you mean '_sigset_t'?
sigset_t all;
^~~~~~~~
_sigset_t
../../src/common/mythread.h:160:2: warning: implicit declaration of function 'sigfillset' [-Wimplicit-function-declaration]
sigfillset(&all);
^~~~~~~~~~
../../src/common/mythread.h:162:2: warning: implicit declaration of function 'mythread_sigmask'; did you mean 'pthread_sigmask'? [-Wimplicit-function-declaration]
mythread_sigmask(SIG_SETMASK, &all, &old);
^~~~~~~~~~~~~~~~
pthread_sigmask
I checked signal.h for sigset_t using gcc -E - <<< "#include <signal.h>" | grep sigset_t and found nothing. Now I've been wondering if this is a MinGW limitation and, if yes, if there is a way around it.
https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-headers/crt/sys/types.h#L110
#ifdef _POSIX
typedef _sigset_t sigset_t;
#endif
It appears this only gets defined if _POSIX is defined. It also is in sys/types.h vs. signal.h...
For a long time i used gcc to compile C code. Sometimes i had to use the optimize("O0") attribute to disable optimizations for a specific function. Now i like to do this with clang.
Assume the following code:
#include <stdio.h>
void __attribute__((optimize("O0"))) blabla(void) {
}
int main(void) {
blabla();
return 0;
}
If i compile it with clang i get this error:
test2.c:3:21: warning: unknown attribute 'optimize' ignored [-Wattributes]
void __attribute__((optimize("O0"))) blabla(void) {
^
1 warning generated.
Then i used google (and also) stackoverflow to find out what attribute is required for clang, because many of them are not in the standard (as soon as i know).
I found this thread:
In clang, how do you use per-function optimization attributes?
If i try the attribute optimize("0") i get this error:
test2.c:3:21: warning: unknown attribute 'optimize' ignored [-Wattributes]
void __attribute__((optimize("0"))) blabla(void) {
^
1 warning generated.
And if i try the attribute optnone i get this error:
test2.c:3:21: warning: unknown attribute 'optnone' ignored [-Wattributes]
void __attribute__((optnone)) blabla(void) {
^
1 warning generated.
I also tried to move the attribute after the function name, but it doesn't work (for some reason there is a warning about GCC?!):
test2.c:3:34: warning: GCC does not allow optnone attribute in this position on a function definition [-Wgcc-compat]
void blabla(void) __attribute__((optnone)) {
^
test2.c:3:34: warning: unknown attribute 'optnone' ignored [-Wattributes]
2 warnings generated.
Another test with the following code:
#include <stdio.h>
[[clang::optnone]]
void blabla(void) {
}
int main(void) {
blabla();
return 0;
}
It produces:
user#ubuntu:/tmp/optxx$ clang test2.c
test2.c:3:1: error: expected identifier or '('
[[clang::optnone]]
^
test2.c:3:2: error: expected expression
[[clang::optnone]]
^
test2.c:8:5: warning: implicit declaration of function 'blabla' is invalid in C99 [-Wimplicit-function-declaration]
blabla();
^
1 warning and 2 errors generated.
Probably i do something wrong, but i cannot see what.
-edit-
clang version:
user#ubuntu:/tmp/optxx$ clang -v
Ubuntu clang version 3.3-16ubuntu1 (branches/release_33) (based on LLVM 3.3)
Target: x86_64-pc-linux-gnu
Thread model: posix
Try the following, clang-style attribute specification:
[[clang::optnone]]
void blabla(void);
EDIT: Clang 3.3 is pretty outdated. Use a more recent version, and your original ((optnone)) code will work.