[Search for users]
[Overall Top Noters]
[List of all Conferences]
[Download this site]
| Title: | MS Windows NT Developers | 
| Notice: | See note 1222 for MS bug reporting info | 
| Moderator: | TARKIN::LIN EIBER | 
|  | 
| 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 05: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.R | Title | User | Personal Name
 | Date | Lines | 
|---|
| 3241.1 |  | GEMEVN::GLOSSOP | Kent Glossop | Fri May 16 1997 07:41 | 5 | 
|  | 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.2 | It worked ! | ADCA01::MADHURIA |  | Tue May 20 1997 05:06 | 7 | 
|  |     Hi,
    
    I incorporated the change suggested by you and it worked. Thanks a lot
    for your help.
    
    Regards,
    -Madhuri
 |