LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-25-2008, 03:23 AM   #1
Serpent77
LQ Newbie
 
Registered: Feb 2008
Location: Atlanta Metro
Distribution: Gentoo, RHEL, CentOS
Posts: 3

Rep: Reputation: 0
Question gcc 4.2.3/popt 1.13 error message - google is no help...


Hi there, let me start out by saying I'm not sure if this question belongs in Programming, or Software, I'm winging it in programming and won't be too offended if I get kicked in the teeth if I'm wrong. Now on to my question:

I'm developing a small command line application that will require some command line arguments. I'm writing this in C (my first program in C) and learned of the popt library. I read the man pages, studied the examples, etc. I set up some code to start configuring my popt configuration and when I get to the point where I call poptGetContext gcc returns an error "warning: passing argument 3 of ‘poptGetContext’ from incompatible pointer type" I've googled this several times, and apparently its a pretty common issue, but no one has posted an answer. The best I've found so far is one person stating the popt.h has an incorrect configuration.

I'm writing this app on Gentoo, with gcc 4.2.3, and popt 1.13. I've defined main as "
Code:
int main (int argc, char** argv)
", and my popt call look like this so far:

Code:
     struct poptOption vcla[]={ /*Valid Command Line Arguments*/
                {"block-size",'b',POPT_ARG_STRING,&block_size,0,"how much data should we copy at once","[B|K|M|G]"},
                {"delay",'d',POPT_ARG_STRING,&wait_time,0,"how much delay should we include between each block we copy","[S|M|H]"},
                {"verbose",'v',0,0,'v',"verbose output",""},
                /*POPT_AUTOHELP*/
                { NULL, 0, 0, NULL, 0 }
                };

        poptContext rcla = poptGetContext(NULL, argc, argv, vcla, 0);
my gcc command looks like this:
gcc -D DEBUG -D_FILE_OFFSET_BITS=64 -march=prescott -pipe -fomit-frame-pointer -O2 slcp.c -o slcp

and finally, the definition in popt.h for the function in question is this:

Code:
poptContext poptGetContext(
                /*@dependent@*/ /*@keep@*/ const char * name,
                int argc, /*@dependent@*/ /*@keep@*/ const char ** argv,
                /*@dependent@*/ /*@keep@*/ const  struct poptOption * options,
                unsigned int flags)
        /*@*/;
(as a side note, do the comments sprinkled throughout this code have any effect?)

any help would be greatly appreciated. A solution will make you my hero for a day. It's a pain having to hard code the new parameters in that should just be provided at the command line.

FYI(1)--the deom app in the man page thows the same error as my app.
FYI(2)--the app I'm writing is called slcp, it allows you to copy a file slowly instead of going as fast as the machine can muster. I'm using it to pull data off a RAID5 array that is running on a crappy card (vendor shall remain unnamed to protect them from their own stupidity.) It's worked quite well allowing me to save a 150GB VMWare virtual hard drive so far if you'd like the source code please contact me, I'm happy to share.

--Serp
 
Old 02-25-2008, 04:48 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Hi

The third argument is argv, maybe if you change the main function to:

int main (int argc, const char** argv)

Not sure if it helps though.
 
Old 02-25-2008, 11:33 AM   #3
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by Serpent77 View Post
I set up some code to start configuring my popt configuration and when I get to the point where I call poptGetContext gcc returns an error "warning: passing argument 3 of ‘poptGetContext’ from incompatible pointer type" I've googled this several times, and apparently its a pretty common issue, but no one has posted an answer. The best I've found so far is one person stating the popt.h has an incorrect configuration.
First, this is only a warning. Many perfectly nice pieces of code throw warnings on some compiler or another because of some technicality. Also, there are instances where a warning-free code is harder to understand than its warning-full counterpart.

In your case, argv has type char**, but the third argument of the function expects a type const char**. So to get rid of the error, you can change the definition of argv to be const-qualified (if you do not intend to modify the contents) as Guttorm pointed out, or you can simply cast to const in the function call:
Code:
poptContext rcla = poptGetContext(NULL, argc, (const char**) argv, vcla, 0);
Quote:
Originally Posted by Serpent77 View Post
(as a side note, do the comments sprinkled throughout this code have any effect?)
Those sprinkled comments do not affect the generated code. They are hints for the static code checker splint (Secure Programming Lint).
 
Old 02-25-2008, 12:13 PM   #4
Serpent77
LQ Newbie
 
Registered: Feb 2008
Location: Atlanta Metro
Distribution: Gentoo, RHEL, CentOS
Posts: 3

Original Poster
Rep: Reputation: 0
Thumbs up getting closer....

Thanks guys, that helped get rid of that warning, now I've got a new error that I've seen reported in relation to using popt as well.

Code:
slcp.c: (.text+0x119): undefined reference to `poptGetContext'
I think if I can get a resolution to this I might be good to go. why would the function be an undefined reference when it's clearly in the header file? I've un-installed and re-installed popt to verify that it's not a corrupt install. I recognize the error references the .text section of the generated assembler code, with an offset, but why would it reference .text on an executable portion of code?

Thanks again for all the help, I've been beating my head against a wall with this for a couple of days now.
 
Old 02-25-2008, 01:33 PM   #5
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by Serpent77 View Post
Thanks guys, that helped get rid of that warning, now I've got a new error that I've seen reported in relation to using popt as well.

Code:
slcp.c: (.text+0x119): undefined reference to `poptGetContext'
This is a linker error (and not a compiler error). Did you specify ‘-lpopt’ at the command for creating the executable? If you are using the same command as in your first post, change it to:
Code:
gcc -D DEBUG -D_FILE_OFFSET_BITS=64 -march=prescott -pipe -fomit-frame-pointer -O2 -lpopt slcp.c -o slcp
 
Old 02-25-2008, 10:54 PM   #6
Serpent77
LQ Newbie
 
Registered: Feb 2008
Location: Atlanta Metro
Distribution: Gentoo, RHEL, CentOS
Posts: 3

Original Poster
Rep: Reputation: 0
Thumbs up Awesome!

Thanks for all the help, that cleared everything up, no more error messages are being reported. Thanks again for the education, this is quite a bit different than my Pascal/Delphi/VB/PHP development.
 
  


Reply

Tags
gcc



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
gcc: installation problem, cannot exec `cc1': No such file or directory Error Message 08h Programming 2 07-20-2006 11:44 AM
What does this gcc error message mean? markhod Programming 2 11-03-2005 07:30 AM
copy constructor causing confusing error message. (gcc c++) qwijibow Programming 6 09-21-2005 08:34 PM
Error Message gcc: Command not found Schmurff Fedora 2 09-27-2004 12:23 PM
gcc: installation problem, cannot exec `cc1': No such file or directory Error Message 08h Linux - Newbie 1 06-01-2004 04:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration