Talk:Executable library: Difference between revisions

Line 35:
 
:::Some languages are released with compilers and interpreters. If they can fashion an example that is constrained to using their interpreters only then they should state that prominently and give their solution. I think Haskel has an interpreter. Their are much lesser known interpreters for what are normally thought of as static languages, such as C. A solution for those might best be put under the actual name of the interpreter as their may be so much distance between the two. --[[User:Paddy3118|Paddy3118]] 02:06, 11 May 2011 (UTC)
 
 
==C debug help request==
Hi guys, I was impressed with the C example enough to try it out but I can't get it to compile on Ubuntu?
 
My efforts so far:
<small><lang c>paddy@paddy-VirtualBox:~/t1$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.5.2-8ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.5/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.5 --enable-shared --enable-multiarch --with-multiarch-defaults=i386-linux-gnu --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib/i386-linux-gnu --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.5 --libdir=/usr/lib/i386-linux-gnu --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-gold --enable-ld=default --with-plugin-ld=ld.gold --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4)
paddy@paddy-VirtualBox:~/t1$ gcc -Wall -W -fPIC -shared -o libhail.so hailstone.c -lc -Wl,-e,hail_main
hailstone.c:1:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
In file included from hailstone.c:2:0:
/usr/include/stdlib.h:140:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__ctype_get_mb_cur_max’
In file included from hailstone.c:2:0:
/usr/include/stdlib.h:337:4: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:367:4: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:369:6: error: nonnull argument with out-of-range operand number (argument 1, operand 4)
/usr/include/stdlib.h:471:29: error: expected ‘)’ before ‘__size’
/usr/include/stdlib.h:473:29: error: expected ‘)’ before ‘__nmemb’
/usr/include/stdlib.h:485:36: error: expected declaration specifiers or ‘...’ before ‘size_t’
In file included from /usr/include/stdlib.h:497:0,
from hailstone.c:2:
/usr/include/alloca.h:33:29: error: expected ‘)’ before ‘__size’
In file included from hailstone.c:2:0:
/usr/include/stdlib.h:503:29: error: expected ‘)’ before ‘__size’
/usr/include/stdlib.h:508:45: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:508:65: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:756:9: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:756:25: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:757:6: error: nonnull argument with out-of-range operand number (argument 1, operand 5)
/usr/include/stdlib.h:761:34: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:761:50: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:762:6: error: nonnull argument with out-of-range operand number (argument 1, operand 4)
/usr/include/stdlib.h:840:6: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:843:6: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:847:31: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:851:31: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:860:38: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:864:36: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:871:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘mbstowcs’
/usr/include/stdlib.h:874:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘wcstombs’
hailstone.c: In function ‘hailstone’:
hailstone.c:8:17: warning: implicit declaration of function ‘malloc’
hailstone.c:8:24: warning: incompatible implicit declaration of built-in function ‘malloc’
hailstone.c:14:33: error: too many arguments to function ‘realloc’
/usr/include/stdlib.h:485:14: note: declared here
hailstone.c: In function ‘hail_main’:
hailstone.c:36:9: warning: implicit declaration of function ‘printf’
hailstone.c:36:9: warning: incompatible implicit declaration of built-in function ‘printf’
paddy@paddy-VirtualBox:~/t1$
paddy@paddy-VirtualBox:~/t1$
paddy@paddy-VirtualBox:~/t1$ more hailstone.{h,c}
::::::::::::::
hailstone.h
::::::::::::::
#ifndef HAILSTONE
#define HAILSTONE
long hailstone(long, long**);
void free_sequence(long *);
#endif/*HAILSTONE*/
 
::::::::::::::
hailstone.c
::::::::::::::
nclude <stdio.h>
#include <stdlib.h>
long hailstone(long n, long **seq)
{
long len = 0, buf_len = 4;
if (seq)
*seq = malloc(sizeof(long) * buf_len);
while (1) {
if (seq) {
if (len >= buf_len) {
buf_len *= 2;
*seq = realloc(*seq, sizeof(long) * buf_len);
}
(*seq)[len] = n;
}
len ++;
if (n == 1) break;
if (n & 1) n = 3 * n + 1;
else n >>= 1;
}
return len;
}
void free_sequence(long * s) { free(s); }
const char my_interp[] __attribute__((section(".interp"))) = "/lib/ld-linux.so.2";
/* "ld-linux.so.2" should be whatever you use on your platform */
int hail_main() /* entry point when running along, see compiler command line */
{
long i, *seq;
long len = hailstone(27, &seq);
printf("27 has %ld numbers in sequence:\n", len);
for (i = 0; i < len; i++) {
printf("%ld ", seq[i]);
}
printf("\n");
free_sequence(seq);
exit(0);
}
 
paddy@paddy-VirtualBox:~/t1$ </lang></small>
--[[User:Paddy3118|Paddy3118]] 12:22, 16 June 2011 (UTC)
Anonymous user