473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Wierd problem with command line args

Hello!
I am facing an extremely frustrating problem with command line
arguments...I have no clue why it is happening. Any help will be
greatly appreciated.

My program: "a.c"
--------------------------------------------------------
#inlclude<stdio.h>

int main(int argc, char * argv[])
{
fprintf(stderr,"%d\n",argc);
fprintf(stderr,"%s",argv[0]);
return 0;
}
--------------------------------------------------------
If I compile this program using
cc a.c
and then run it using
../a.out arg1 arg2
the program displays
--------
3
a.out
--------

which is fine!!

However, if I compile & link this program separately using
cc -c a.c
ld -lc -ldl a.c

and run it using
../a.out arg1 arg2
the program displays
--------
0
Segmentation Fault, Core dumped
--------
I cannot understand this at all. Please help....

vj

Jul 28 '06 #1
5 1499
"vjonweb" <vi*****@gmail.comwrites:
I am facing an extremely frustrating problem with command line
arguments...I have no clue why it is happening. Any help will be
greatly appreciated.
The problem is how you're invoking the linker. That's an issue
to discuss in a newsgroup about your implementation, e.g. a Linux
newsgroup if you're using Linux.
--
"The fact that there is a holy war doesn't mean that one of the sides
doesn't suck - usually both do..."
--Alexander Viro
Jul 28 '06 #2

Ben Pfaff wrote:
"vjonweb" <vi*****@gmail.comwrites:
I am facing an extremely frustrating problem with command line
arguments...I have no clue why it is happening. Any help will be
greatly appreciated.

The problem is how you're invoking the linker. That's an issue
to discuss in a newsgroup about your implementation, e.g. a Linux
newsgroup if you're using Linux.
--
"The fact that there is a holy war doesn't mean that one of the sides
doesn't suck - usually both do..."
--Alexander Viro
Can you please tell me what is the problem with the invocation...?I was
not sure if this was platform specific which is why I posted it here
originally...

VJ

Jul 28 '06 #3
"vjonweb" <vi*****@gmail.comwrites:
Ben Pfaff wrote:
>"vjonweb" <vi*****@gmail.comwrites:
I am facing an extremely frustrating problem with command line
arguments...I have no clue why it is happening. Any help will be
greatly appreciated.

The problem is how you're invoking the linker. That's an issue
to discuss in a newsgroup about your implementation, e.g. a Linux
newsgroup if you're using Linux.

Can you please tell me what is the problem with the invocation...?I was
not sure if this was platform specific which is why I posted it here
originally...
And now you've been told that it *is* platform specific, so you
need to inquire about it someplace related to your platform.
--
"I hope, some day, to learn to read.
It seems to be even harder than writing."
--Richard Heathfield
Jul 29 '06 #4
"vjonweb" <vi*****@gmail.comwrites:
I am facing an extremely frustrating problem with command line
arguments...I have no clue why it is happening. Any help will be
greatly appreciated.

My program: "a.c"
--------------------------------------------------------
#inlclude<stdio.h>

int main(int argc, char * argv[])
{
fprintf(stderr,"%d\n",argc);
fprintf(stderr,"%s",argv[0]);
return 0;
}
It's already been pointed out that your problem is platform-specific,
but I'll point out a couple of things that aren't.

You misspelled "include". Apparently you've re-typed your program.
Don't do that. Copy-and-paste the *exact* program as you fed it to
the compiler; otherwise we can't guess which errors are in the
original program that you didn't show us, and which were introduced
when you re-typed it.

[snip]
However, if I compile & link this program separately using
cc -c a.c
ld -lc -ldl a.c

and run it using
./a.out arg1 arg2
the program displays
--------
0
Segmentation Fault, Core dumped
--------
Now this part is platform-specific.

<OT>
"ld" is the linker. The linker works on object files, not on source
files; the correct command line would be "ld -lc -ldl a.o".
Copying-and-pasting command lines is just as important as
copying-and-pasting source code.
</OT>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 29 '06 #5
In article <11**********************@s13g2000cwa.googlegroups .com"vjonweb" <vi*****@gmail.comwrites:
Can you please tell me what is the problem with the invocation...?I was
not sure if this was platform specific which is why I posted it here
originally...
It depends on your platform. The C language states nothing about linking.
If I perform as you wrote the response is:
Linux.i686/nissiros.cst/ksh: cc -c a.c
Linux.i686/nissiros.cst/ksh: ld -lc -ldl a.c
a.c: file not recognized: File format not recognized
not entirely what you wrote. If I change the second line to:
Linux.i686/nissiros.cst/ksh: ld -lc -ldl a.o
ld: warning: cannot find entry symbol _start; defaulting to 08048214
Linux.i686/nissiros.cst/ksh:
again not entirely what you wrote. Please, this appears to be Linux
specific (and also depending on the version of Linux you are using).

--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Jul 30 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: se7en | last post by:
okay, i cant seem to run a file with another file as an argument. e.g I want to send the file "x.met" as an argument when running the file "y.py" thanx -python newbie-
9
by: Manlio Perillo | last post by:
Regards. In the standard library there are two modules for command line parsing: optparse and getopt. In the Python Cookbook there is another simple method for parsing, using a docstring. ...
2
by: JS | last post by:
I read the following in som sample code: function createOpts(sel){ var s = new Array(); var num = 0, txt = "bo"; var ar = opt = null; var n = sel.selectedIndex; var args =...
9
by: santosh | last post by:
Hello all, I've put together a small program to count the number of characters and 'words' in a text file. The minimum length of a word, (in terms of no. of characters), as well as word...
1
by: Brad | last post by:
I have an issue trying to execute commands in a web service. The command starts under the specified user. However, it never completes its execution. I can execute simple commands like "echo HELLO"...
1
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this...
6
by: shana07 | last post by:
Friends, I wish to consult about this big arithmetic program. This program basically is calculating big numbers. It work great from command prompt, for instance: java bigal 99999999999999999 + 5....
6
by: tvaughan77 | last post by:
Hi, I have some code that I want to use to run a command line utility and I want to be able to run it from an aspx page running under IIS. The command line utility is a local utility running on...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.