Running a C program

View: New views
8 Messages — Rating Filter:   Alert me  

Running a C program

by NeillHog :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello!
This is my first posting and I apologise in advance for any rules I may, inadvertently, be breaking.
I am definitely not a Linux guru but I am willing to learn.

I wrote a quick test program
#include <stdio.h>
main()
{
  printf("neill\n");
}

and compiled it on my kubuntu PC with gcc -o test test.c
Then chmod 744 test and ./test
It worked as expected.

I then transferred the test program to my NSLU (with unslung) and did
chmod 744 test and ./test

The result was ./test: ./test: 1: Syntax error: "(" unexpected

Could some one help me by explaining my error.
Thank you in advance.

Neill

Re: Running a C program

by Sébastien Lorquet :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello and welcome!

your "error" is simple: the nslu does not have the same CPU as your Ubuntu
PC, so it cannot run programs compiled on your pc:
Your pc has a x86 cpu.
The slug has an ARM cpu.

You must either "cross compile" your program for the slug, or run a
on-slug-board gcc adapted to your slug.

1) cross compiling - that means using a gcc that runs on your pc but
generates code for the slug. personnally, I don't know where to find a
simple toolchain to do this - but other people here know it, i'm sure.

2) native compiling on the slug - this requires having added some swap on a
usb stick, then installing the following ipkgs, possibly from optware, I
don't know unslung (I'm a slugos user):
binutils binutils-symlinks cpp cpp-symlinks gcc gcc-symlinks

then you can run the gcc -o test test.c on the slug itself, and it will work
as expected (but not on a pc :) )

Regards
Sebastien

On Wed, Jun 17, 2009 at 10:47 PM, NeillHog <Neill@...> wrote:

>
> Hello!
> This is my first posting and I apologise in advance for any rules I may,
> inadvertently, be breaking.
> I am definitely not a Linux guru but I am willing to learn.
>
> I wrote a quick test program
> #include <stdio.h>
> main()
> {
>  printf("neill\n");
> }
>
> and compiled it on my kubuntu PC with gcc -o test test.c
> Then chmod 744 test and ./test
> It worked as expected.
>
> I then transferred the test program to my NSLU (with unslung) and did
> chmod 744 test and ./test
>
> The result was ./test: ./test: 1: Syntax error: "(" unexpected
>
> Could some one help me by explaining my error.
> Thank you in advance.
>
> Neill
>
> --
> View this message in context:
> http://www.nabble.com/Running-a-C-program-tp24080049p24080049.html
> Sent from the Nslu2 - Linux mailing list archive at Nabble.com.
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>

Re: Running a C program

by NeillHog :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Sébastien Lorquet wrote:
.....
You must either "cross compile" your program for the slug, or run a
on-slug-board gcc adapted to your slug.
...
2) native compiling on the slug - ...
Hello Sebastian!
Great info. Thank you. I'll get back to you with the results when I have tried it.
Neill

Re: Running a C program

by NeillHog :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sébastien Lorquet wrote:
native compiling on the slug - this requires having added some swap on a
usb stick, then installing the following ipkgs, possibly from optware, I
don't know unslung (I'm a slugos user):
binutils binutils-symlinks cpp cpp-symlinks gcc gcc-symlinks

then you can run the gcc -o test test.c on the slug itself, and it will work
as expected (but not on a pc :) )
Thanks again
As I wrote, may device is unslung.
With ipkg install crosstool-native I installed a compiler and that allows me to compile on the NSLU2.
Neill

Re: Running a C program

by NeillHog :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sébastien Lorquet wrote:
..... or run a on-slug-board gcc adapted to your slug.
Sebastien's help was very useful.
I have now managed to compile the program that I want to use on the slug and it appears to have compiled.
When I try to start it, I get a message as follows
# ./vcontrold-arm
./vcontrold-arm: error while loading shared libraries: libxml2.so.2: cannot open shared object file: No such file or directory


The author of the program told me that I needed to have the header files for libxml2 installed.
Maybe this is my problem. Could any one help me with instructions on how to install the header files?
Or point me at suitable instructions.

I have already done ipkg install libxml2 but I don't think that installed any header files.


Thank you!
Neill

RE: Running a C program

by nww02 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


 

Whenever you're doing development on Linux, you can usually append "-dev" or "-devel" on the name of the package to get the headers and libraries for whatever it is you're tyring to work with.. so obtaining "libjpg" (by apt-get or rpm or whatever) will let you use programs pre-compiled to work with Jpgs (like ImageMagick for example), but "libjpg-devel" will allow you to write programs to use it.

 

 

These are general Linux programming questions, so probably a little off topic for this forum.  Probably a good idea is to get a book on Linux programming (there's LOADS of free PDFs and HTML files on the internet about it!).

 

 

I hope this helps.  Good luck with your programming! The slug is a great tool for writing quick utils. :)

 

N.

 



--

Nick Walton








 


To: nslu2-linux@...
From: Neill@...
Date: Tue, 23 Jun 2009 12:38:19 -0700
Subject: Re: [nslu2-linux] Running a C program









Sébastien Lorquet wrote:
>
> ..... or run a on-slug-board gcc adapted to your slug.
>

Sebastien's help was very useful.
I have now managed to compile the program that I want to use on the slug and
it appears to have compiled.
When I try to start it, I get a message as follows
# ./vcontrold-arm
./vcontrold-arm: error while loading shared libraries: libxml2.so.2: cannot
open shared object file: No such file or directory

The author of the program told me that I needed to have the header files for
libxml2 installed.
Maybe this is my problem. Could any one help me with instructions on how to
install the header files?
Or point me at suitable instructions.

I have already done ipkg install libxml2 but I don't think that installed
any header files.

Thank you!
Neill
--
View this message in context: http://www.nabble.com/Running-a-C-program-tp24080049p24172302.html
Sent from the Nslu2 - Linux mailing list archive at Nabble.com.









_________________________________________________________________
Get the best of MSN on your mobile
http://clk.atdmt.com/UKM/go/147991039/direct/01/

Re: Running a C program

by Drew Gibson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



NeillHog wrote:

> I have now managed to compile the program that I want to use on the slug and
> it appears to have compiled.
> When I try to start it, I get a message as follows
> # ./vcontrold-arm
> ./vcontrold-arm: error while loading shared libraries: libxml2.so.2: cannot
> open shared object file: No such file or directory
>
> The author of the program told me that I needed to have the header files for
> libxml2 installed.
>
>  
......
> I have already done ipkg install libxml2 but I don't think that installed
> any header files.
>  

Hi Neill,

I'm not a developer but I've had my share of this type of issue, so
here's a Hamfisted Hacker's guide to "lib not found"...

It looks like the program cannot find the libxml binary at runtime
rather than the headers at build time (which is when it would need the
header files). You have libxml2 installed (double check it installed
OK!) so either the file is there but not in the expected location or it
is a newer or older version of the library and your prog is being too
specific.

Unslung has some "nuances" that make it a little more "interesting" than
normal Linux.
The stock Linksys Linux firmware is not removed but "overlayed" with the
additional features that make it "unslung". This additional stuff is
generally under /opt with scripts modified to run the unslung version in
preference to the Linksys version of some code. This means that a file
could be in the main file structure or in the /opt structure.

The library libxml2.so.2 may be installed but your program just can't
find it, have a look around (check out the find command) or perhaps
libxml2.so or libxml2.so.3 is there but not libxml2.so.2 (making a
symlink works 4 times out of 5)

good luck,

regards,

Drew



Re: Running a C program

by brian_zhou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Optware ipkg installs libs to /opt/lib, which is not a usual place that the system automatically looks for shared lib. You can work around that with LD_LIBRARY_PATH environment variable; or you can add "-rpath /opt/lib" to your ld command line, or "-Wl,-rpath,/opt/lib" if you use gcc to link.

We recommend to use optware development framework and create ipk. This kind of problem has already been taken care of in the framework. And your work can very likely be re-used for other optware targets. In the case of optware, we don't always package development headers, since they are staged in the staging directory.

-Brian

--- In nslu2-linux@..., NeillHog <Neill@...> wrote:

>
>
>
> Sébastien Lorquet wrote:
> >
> > ..... or run a on-slug-board gcc adapted to your slug.
> >
>
> Sebastien's help was very useful.
> I have now managed to compile the program that I want to use on the slug and
> it appears to have compiled.
> When I try to start it, I get a message as follows
> # ./vcontrold-arm
> ./vcontrold-arm: error while loading shared libraries: libxml2.so.2: cannot
> open shared object file: No such file or directory
>
> The author of the program told me that I needed to have the header files for
> libxml2 installed.
> Maybe this is my problem. Could any one help me with instructions on how to
> install the header files?
> Or point me at suitable instructions.
>
> I have already done ipkg install libxml2 but I don't think that installed
> any header files.
>
>
> Thank you!
> Neill
> --
> View this message in context: http://www.nabble.com/Running-a-C-program-tp24080049p24172302.html
> Sent from the Nslu2 - Linux mailing list archive at Nabble.com.
>