[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference decwet::nt-developers

Title:MS Windows NT Developers
Notice:See note 1222 for MS bug reporting info
Moderator:TARKIN::LINEIBER
Created:Mon Nov 11 1991
Last Modified:Tue Jun 03 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3247
Total number of notes:15633

3241.0. "Referencing C++ variables from C files" by ADCA01::MADHURIA () Fri May 16 1997 09:13

    Hi,


    We are porting an application from Digital Unix to windows NT. The
    application is developed using C, C++, FORTRAN.

    We have some variables defined in C++ files and making use of these 
    variables in our C files.

    For Example,

    C++ code
    --------
    extern "C" void test();
    int var1;
    main()
    {
       test();
    }

    c code
    ------

    #include <stdio.h>
    extern int var1;
    void test()
    {
        printf ("\n %d",var1);
    }

    During linking these files, the linker gives an unresolved external
    symbol error for the variable var1.

    How to go about solving this problem ?

    Thanks in advance

    -Madhuri
    Digital India

    
               
T.RTitleUserPersonal
Name
DateLines
3241.1GEMEVN::GLOSSOPKent GlossopFri May 16 1997 11:415
You need to declare the variable as having C linkage as well:

extern "C" int var1;

(MS VC++ mangles data names in addition to function names.)
3241.2It worked !ADCA01::MADHURIATue May 20 1997 09:067
    Hi,
    
    I incorporated the change suggested by you and it worked. Thanks a lot
    for your help.
    
    Regards,
    -Madhuri