Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

alt_busy_sleep

Dear All,

My code need to call alt_busy_sleep(), but the compiler report the following error.

Linking TestCPP.elf...

obj/main.o(.gnu.linkonce.t._ZN13JaidTestClass18TestOSDBlockAdjustEv+0x18c): In function `JaidTestClass::TestOSDBlockAdjust()':

C:/altera/OSD_FINAL/JaidNiosOSD/software/TestCPP/TestClass/TestClass.hpp:352: undefined reference to `alt_busy_sleep(unsigned int)'

I have include the necessary header file in my code, # include "priv/alt_busy_sleep.h"

also I can find alt_busy_sleep.c in C:\altera\kits\nios2_51\components\altera_nios2\HAL\src.

Why the linker can't find alt_busy_sleep yet. Evenly I copy alt_busy_sleep.c to project folder, but the error still exist...

Anybody help...

Thanks in advance http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/laugh.gif

5 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    nios2_5.1

    quartusii_51_sp1_web_edition.exe

    somebody tell me that:

    Do you use C and C++ files in your project? You should declare the function alt_busy_sleep() is a C function if you use it in a C++ file.

    But I don&#39;t know how can I declare the function alt_busy_sleep() is a C function in C++ files.

    Also I need to understand why.

    Thanks for your reply....
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    originally posted by david_cai@Jul 6 2006, 10:56 AM

    dear all,

    my code need to call alt_busy_sleep(), but the compiler report the following error.

    linking testcpp.elf...

    obj/main.o(.gnu.linkonce.t._zn13jaidtestclass18testosdblockadjustev+0x18c): in function `jaidtestclass::testosdblockadjust()&#39;:

    c:/altera/osd_final/jaidniososd/software/testcpp/testclass/testclass.hpp:352: undefined reference to `alt_busy_sleep(unsigned int)&#39;

    i have include the necessary header file in my code, # include "priv/alt_busy_sleep.h"

    also i can find alt_busy_sleep.c in c:\altera\kits\nios2_51\components\altera_nios2\hal\src.

    why the linker can&#39;t find alt_busy_sleep yet. evenly i copy alt_busy_sleep.c to project folder, but the error still exist...

    anybody help...

    thanks in advance http://forum.niosforum.com/work2/style_emoticons/<#emo_dir#>/laugh.gif

    <div align='right'><{post_snapback}> (index.php?act=findpost&pid=16681)

    --- quote end ---

    --- Quote End ---

    Hi David_Cai!

    I had this type of error when I had q5.1 and nios 5.0!

    Later I have installed Nios 5.1 and error had not occired.

    Please give more specific information about your system

    version of Q and Nios http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Dear All,

    I have solved this issue.

    The answer is :

    declare the function alt_busy_sleep() is a C function if you use it in a C++ file

    extern "C" unsigned int alt_busy_sleep (unsigned int us);

    But I still don&#39;t know why...

    Anybody help?

    David
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi David

    The compiler rules for C and C++ are some what differ. when you write any code in C and if you want to access that function or structure in C++ file then explicitly you have to tell to compiler and it will call that perticular function( or Build) as a C style rules and gives no error.

    At the same time you if you want to access C++ code in C file then also you have to define a Macro for that.

    Here i am passing you one link..Just go through this and get the detail answer.

    If you have any query then Ask me

    http://developers.sun.com/prodtech/cc/articles/mixing.html (http://developers.sun.com/prodtech/cc/articles/mixing.html)

    Best Regards,

    slsnios
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks very much...

    I think that the basic reason is:

    The function name after compilation is different in C from that in C++. The declaration is necessary for both sides.