Skip to content
This repository has been archived by the owner on Jul 22, 2021. It is now read-only.

trip.c does not compile #1

Closed
aeosynth opened this issue Oct 28, 2010 · 6 comments
Closed

trip.c does not compile #1

aeosynth opened this issue Oct 28, 2010 · 6 comments

Comments

@aeosynth
Copy link

[james@arch ~]$ cc --version
cc (GCC) 4.5.1
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[james@arch tmp]$ cc trip.c
trip.c: In function ‘init_lfsr113’:
trip.c:55:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
trip.c:55:3: note: use option -std=c99 or -std=gnu99 to compile your code
trip.c: In function ‘main’:
trip.c:98:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
trip.c:105:11: error: redefinition of ‘i’
trip.c:98:11: note: previous definition of ‘i’ was here
trip.c:105:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
trip.c: In function ‘trip_search’:
trip.c:148:5: error: ‘for’ loop initial declarations are only allowed in C99 mode

[james@arch tmp]$ cc trip.c -std=c99
trip.c: In function ‘init_lfsr113’:
trip.c:50:1: warning: implicit declaration of function ‘seed48’
trip.c:50:27: warning: initialization makes pointer from integer without a cast
trip.c:51:3: warning: implicit declaration of function ‘nrand48’
trip.c: In function ‘main’:
trip.c:76:3: warning: implicit declaration of function ‘getopt’
trip.c:82:17: error: ‘optarg’ undeclared (first use in this function)
trip.c:82:17: note: each undeclared identifier is reported only once for each function it appears in
trip.c:92:6: error: ‘optind’ undeclared (first use in this function)
trip.c:97:3: warning: implicit declaration of function ‘srand48’
trip.c:100:5: warning: implicit declaration of function ‘lrand48’

[james@arch tmp]$ cc trip.c -std=gnu99
/tmp/ccBidljP.o: In function `main':
trip.c:(.text+0x3f1): undefined reference to `pthread_create'
/tmp/ccBidljP.o: In function `trip_search':
trip.c:(.text+0x6a5): undefined reference to `pcre_compile'
trip.c:(.text+0x6e9): undefined reference to `pcre_study'
trip.c:(.text+0x730): undefined reference to `pcre_info'
trip.c:(.text+0x86d): undefined reference to `DES_fcrypt'
trip.c:(.text+0x8a4): undefined reference to `pcre_exec'
collect2: ld returned 1 exit status

trip-std.c has similar errors

edit: added gnu99, trip-std.c note

@lilyanatia
Copy link
Owner

learn to use your compiler.
-std=c99 -lpthread -lpcre -lcrypto

or, since your libc is apparently broken unless you use -std=gnu99,
-std=gnu99 -lpthread -lpcre -lcrypto

@aeosynth
Copy link
Author

I'm not a c hacker, so forgive me. This would have been easier if you had a readme. Could I get the right options to compile trip-std.c by any chance?

[james@arch trip]$ cc --std=gnu99 trip-std.c
trip-std.c: In function ‘trip_search’:
trip-std.c:124:5: warning: implicit declaration of function ‘crypt’
trip-std.c:124:5: warning: passing argument 2 of ‘memcpy’ makes pointer from integer without a cast
/usr/include/string.h:44:14: note: expected ‘const void * restrict’ but argument is of type ‘int’
/tmp/ccBr4xk0.o: In function `main':
trip-std.c:(.text+0x3c8): undefined reference to `pthread_create'
/tmp/ccBr4xk0.o: In function `trip_search':
trip-std.c:(.text+0x771): undefined reference to `crypt'
collect2: ld returned 1 exit status

@lilyanatia
Copy link
Owner

if your system doesn't have crypt, trip-std.c won't work for you.
if you can fix that, you'll need to link it against libpthread (-lpthread).

@aeosynth
Copy link
Author

I can get it to compile with -std=gnu99 -lpthread -lcrypt, but it just segfaults.

[james@arch trip]$ cc trip-std.c -o trip-std -std=gnu99 -lpthread -lcrypt 
trip-std.c: In function ‘trip_search’:
trip-std.c:124:5: warning: implicit declaration of function ‘crypt’
trip-std.c:124:5: warning: passing argument 2 of ‘memcpy’ makes pointer from integer without a cast
/usr/include/string.h:44:14: note: expected ‘const void * restrict’ but argument is of type ‘int’
[james@arch trip]$ ./trip-std wat
Segmentation fault

I'm on Arch Linux btw.

@lilyanatia
Copy link
Owner

those warnings are because crypt isn't declared in unistd.h like it should be.
"implicit declaration" means that it's assuming it's int crypt(int), when it should be char *crypt(const char *, const char *). that's probably why you're getting a segfault.
you could try adding a declaration for crypt, but the right way to fix it would be to figure out why your unistd.h doesn't declare crypt.

@aeosynth
Copy link
Author

aeosynth commented Nov 5, 2010

I figured it out - the declaration in unistd.h is guarded by #ifdef __USE_XOPEN; adding #define __USE_XOPEN to trip-std.c makes it work.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants