naive newbie wants to call add_timer()

naive newbie wants to call add_timer()

Post by joh.. » Wed, 18 Aug 1999 04:00:00



I'm trying to get some rudimentary understanding of calling a system
function.

// itimetest.c
#include <linux/timer.h>
int main()
{
    timer_list tl;  // (todo: initialize tl properly!)
    add_timer( &tl);

Quote:}


/tmp/ccNO5zm3.o: In function `main':
/tmp/ccNO5zm3.o(.text+0xb): undefined reference to
`add_timer(timer_list *)'

So I'm trying to figure out, how do I tell the linker about the
function add_timer?

Thanks,
John
john-clonts(AT)reliantenergy(DOT)com

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

 
 
 

naive newbie wants to call add_timer()

Post by Kaz Kylhe » Wed, 18 Aug 1999 04:00:00



>I'm trying to get some rudimentary understanding of calling a system
>function.

>// itimetest.c
>#include <linux/timer.h>
>int main()

What are you trying to do? The main function is for starting hosted programs.
Kernel code doesn't use main(). A loadable module is expected to implement
the init_module and cleanup_module functions.

>{
>    timer_list tl;  // (todo: initialize tl properly!)
>    add_timer( &tl);

>}


>/tmp/ccNO5zm3.o: In function `main':
>/tmp/ccNO5zm3.o(.text+0xb): undefined reference to
>`add_timer(timer_list *)'

Use gcc, not g++! The code is C (with non-conforming C++ comments) not C++.
If you use g++, then even files with a .c suffix get treated as C++.

The fact that the linker is complaining about ``add_timer(timer_list *)''
is a big cluestick that the code was compiled as c++. There is type
information in the object file! You wouldn't be able to tell from a C compiled
object file that add_timer has a ``timer_list *'' parameter.
In other words, the compiler generated a mangled name with type info
encoded.

Secondly, the add_timer function is not in any library. It is in the
kernel. The references to kernel symbols are resolved when you insert
the module into the kernel. A module must be built as an object with
unresolved symbols (.o file). For example:

        gcc -D__KERNEL__ mydriver.c -c

Then if all goes well,

        insmod ./mydriver.o

Even if you succeed in doing this, you won't be able to resolve the
add_timer reference if you compile the thing as C++, unless you
wrap the kernel headers in extern "C" { /*... */ }.

 
 
 

naive newbie wants to call add_timer()

Post by Peter Pointne » Thu, 19 Aug 1999 04:00:00



> I'm trying to get some rudimentary understanding of calling a system
> function.
> // itimetest.c
> #include <linux/timer.h>
> int main()
> {
>     timer_list tl;  // (todo: initialize tl properly!)
>     add_timer( &tl);
> }

> /tmp/ccNO5zm3.o: In function `main':
> /tmp/ccNO5zm3.o(.text+0xb): undefined reference to
> `add_timer(timer_list *)'
> So I'm trying to figure out, how do I tell the linker about the
> function add_timer?

You don't. add_timer is for use in the kernel (including loadable
modules). A normal application can only use the system calls to the
kernel, and you do that normally by using the function calls provided
by libc.

Peter

 
 
 

naive newbie wants to call add_timer()

Post by joh.. » Thu, 19 Aug 1999 04:00:00


Ok, thanks.  I guess I'll go try and learn about modules.

Also, is there no service available to a "hosted program" that offers
periodic timer/callback (as opposed to sleep()) ?

Thanks,
John





> >I'm trying to get some rudimentary understanding of calling a system
> >function.

> >// itimetest.c
> >#include <linux/timer.h>
> >int main()

> What are you trying to do? The main function is for starting hosted
programs.
> Kernel code doesn't use main(). A loadable module is expected to
implement
> the init_module and cleanup_module functions.

> >{
> >    timer_list tl;  // (todo: initialize tl properly!)
> >    add_timer( &tl);

> >}


> >/tmp/ccNO5zm3.o: In function `main':
> >/tmp/ccNO5zm3.o(.text+0xb): undefined reference to
> >`add_timer(timer_list *)'

> Use gcc, not g++! The code is C (with non-conforming C++ comments) not
C++.
> If you use g++, then even files with a .c suffix get treated as C++.

> The fact that the linker is complaining about ``add_timer(timer_list
*)''
> is a big cluestick that the code was compiled as c++. There is type
> information in the object file! You wouldn't be able to tell from a C
compiled
> object file that add_timer has a ``timer_list *'' parameter.
> In other words, the compiler generated a mangled name with type info
> encoded.

> Secondly, the add_timer function is not in any library. It is in the
> kernel. The references to kernel symbols are resolved when you insert
> the module into the kernel. A module must be built as an object with
> unresolved symbols (.o file). For example:

>    gcc -D__KERNEL__ mydriver.c -c

> Then if all goes well,

>    insmod ./mydriver.o

> Even if you succeed in doing this, you won't be able to resolve the
> add_timer reference if you compile the thing as C++, unless you
> wrap the kernel headers in extern "C" { /*... */ }.

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
 
 
 

naive newbie wants to call add_timer()

Post by Kaz Kylhe » Thu, 19 Aug 1999 04:00:00



>Ok, thanks.  I guess I'll go try and learn about modules.

>Also, is there no service available to a "hosted program" that offers
>periodic timer/callback (as opposed to sleep()) ?

You can use setitimer() to have a periodic alarm signal delivered to your
process, or use LinuxThreads to create a timer thread which performs
callouts.
 
 
 

naive newbie wants to call add_timer()

Post by elli » Thu, 19 Aug 1999 04:00:00



>I'm trying to get some rudimentary understanding of calling a system
>function.

>// itimetest.c
>#include <linux/timer.h>
>int main()
>{
>    timer_list tl;  // (todo: initialize tl properly!)
>    add_timer( &tl);

>}


>/tmp/ccNO5zm3.o: In function `main':
>/tmp/ccNO5zm3.o(.text+0xb): undefined reference to
>`add_timer(timer_list *)'

>So I'm trying to figure out, how do I tell the linker about the
>function add_timer?

You don't because add_timer is a kernel function.  You use it in a
kernel module not a userspace program.

--
http://www.fnet.net/~ellis/photo/linux.html

 
 
 

1. Wanted: Suggestions for automounting floppies for naive users

Hi all,

    I run a public Internet access network based on Linux (the only
    choice for a stable system that allows a virtualy unlimited number
    of people to have private email addresses etc).

    For sometime, people have wanted to be able to save their downloads
    to a floppy, to take away.

    The primary interface to the system is Netscape. The users typically
    have not used a computer before at all, or if they have, they've
    used Windoze.

    What I want is for the users to be able to stick a floppy in,
    select save from the Netscape File menu, have Netscape save to the
    floppy, and let them pull the floppy out once it's done. This has
    to work *very* reliably, as the users are naive, and since it is a
    public access system, it's difficult to educate people about any
    idiosyncracies (such as "wait a while before you pull the floppy out
    to make sure the system has flushed its buffers").

    I tried fdmount, but it was unable to get it to recognise a media
    change reliably. The README said that not all floppy hardware was
    well supported in this regard.

    My next thought was to use AMD with a short expiry time on the
    mount, and just mount the floppy when the user tries to save to it.
    Having the mount time expire immediately, should mean that as soon
    as the write is finished, the disk is unmounted.

        I'm yet to try this.  Any other ideas or solutions would be appreciated.

    In many ways, this is a really key usability issue for Linux as
    far as novice users go, and I'll be publishing whatever solution
    works best with the hope that support for this might make it into a
    standard Linux distribution sometime soon.

Best,

Mark

PS Any ideas on how to get Netscape to default to writing to the
directory the floppy is mounted in would also be greatly appreciated.
--
---------------------------------------------------------------------------

"When all our time is being saved, none of it is left for experiencing."

2. libfl.a / Flex input streams

3. Help a naive newbie

4. How to find if a script is being run as root user

5. init_timer add_timer del timer

6. Linux Client and Win NT Proxy

7. which library add_timer() is exist in?

8. messed up my XF86Config file

9. Suse 6.4: add_timer linking problem

10. add_timer??

11. using timer_list / add_timer / del_timer

12. add_timer and the timer_list_struct

13. how to link add_timer, del_timer??