Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

VC++ Programming Guide

Solved!
Go to solution

I need help getting started with Microsoft Visual C++ 2008 Express Edition. 

 

I get a Link error when trying to call ibdev.  I have already added include directories:

C:\Program Files\National Instruments\Shared\ExternalCompilerSupport\C\include

Before adding that include dir was added the "ni4882.h" was not found. 

 

This is in the main():
   #define BDINDEX               0     // Board Index
   #define PRIMARY_ADDR_OF_DMM   22    // Primary address of device
   #define NO_SECONDARY_ADDR     0     // Secondary address of device
   #define TIMEOUT               T10s  // Timeout value = 10 seconds
   #define EOTMODE               1     // Enable the END message
   #define EOSMODE               0     // Disable the EOS mode

   Dev = ibdev(BDINDEX, PRIMARY_ADDR_OF_DMM, NO_SECONDARY_ADDR,
               TIMEOUT, EOTMODE, EOSMODE);

 

This is the error.

 

Hope0001.obj : error LNK2019: unresolved external symbol _ibdev@24 referenced in function _main

MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

 

Thank you VERY much for any help!

0 Kudos
Message 1 of 17
(8,679 Views)

Hi,

 

Did you add the gpib object file  (gpib-32.obj) to your project?

 

It should be at

 

C:\Program Files\National Instruments\NI-488.2\Languages\Microsoft C

 

Curt

0 Kudos
Message 2 of 17
(8,670 Views)

Also,

 

Ni4882.h is part of the measurement studio library for gpib.

 

The ibdev function is in the standard NI gpib library

 

You should also include the "Decl-32.h" file in your project.

 

Curt

Message 3 of 17
(8,668 Views)
I keep going over the same ground and not getting it to work. One thing is I don't see how to add an .obj file to the "project". The best I found was Additional Dependencies in input under linker. The format is strange and it did not like the space in the name like "Program Files" I got around that with double quotes. I think I need to use ni4882.obj to match ni4882.h. I was not able to add a 2nd .obj file like the gpib-32.obj that was suggested. I just want to send and recieve GPIB commands inside my C program.
0 Kudos
Message 4 of 17
(8,660 Views)

Chris,

 

I assume you're working with the Devquery.c example located at \Documents and Settings\All Users\Documents\National Instruments\NI-488.2\Examples\Standard C\Devquery. If you look at the readme.txt at that location, it gives you command-line statements to compile your application. Can you confirm this works for you?

 

cl /I"%NIEXTCCOMPILERSUPP%\include" Devquery.c "%NIEXTCCOMPILERSUPP%\lib32\msvc\ni4882.obj" /MD

 

 I confirmed through the VS2008 command prompt that this indeed worked. If you need the location of the necessary headers/object files, you can type echo %NIEXTCCOMPILERSUPP% into command prompt.

Warm regards,

pBerg
Message 5 of 17
(8,598 Views)

First off thanks for your help.  I tried your commands and it appears to work.  There may be an extra "\" at the end of the environment var(NIEXTCCOMPILERSUPP), but it didn't stop the compile nor link.  I'll paste the input and out from that "DOS window" below.  I will like to use the Integrated Development Environment (IDE) which I think is called "Microsoft Visual C++ 2008 Express Edition" (MSVC).  MSVC is a nice debug tool because of the stop, single line stepping and all that stuff. 

 

How do I get from command line typing to clicking in MSVC? 

 

Also note that this PC has had many version of NI drivers installed in past years.

 

(Hope the long lines don't wrap into something hard to read.)

 

C:\Documents and Settings\All Users\Documents\National Instruments\NI-488.2\Examples\Standard C\Devquery>dir
 Volume in drive C has no label.
 Volume Serial Number is C45E-FD26

 Directory of C:\Documents and Settings\All Users\Documents\National Instruments\NI-488.2\Examples\Standard C\Devquery

03/11/2010  11:33 AM    <DIR>          .
03/11/2010  11:33 AM    <DIR>          ..
12/18/2009  12:50 PM             5,010 Devquery.c
03/12/2010  10:59 AM             4,886 ReadMe-2.txt
12/18/2009  12:50 PM             3,040 ReadMe.txt
               3 File(s)         12,936 bytes
               2 Dir(s)  173,155,880,960 bytes free

C:\Documents and Settings\All Users\Documents\National Instruments\NI-488.2\Examples\Standard C\Devquery>cl /I"%NIEXTCCOMPILERSUPP%\include" Devquery.c "%NIEXTC
COMPILERSUPP%\lib32\msvc\ni4882.obj" /MD
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

Devquery.c
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:Devquery.exe
Devquery.obj
"C:\Program Files\National Instruments\Shared\ExternalCompilerSupport\C\\lib32\msvc\ni4882.obj"

C:\Documents and Settings\All Users\Documents\National Instruments\NI-488.2\Examples\Standard C\Devquery>dir
 Volume in drive C has no label.
 Volume Serial Number is C45E-FD26

 Directory of C:\Documents and Settings\All Users\Documents\National Instruments\NI-488.2\Examples\Standard C\Devquery

03/18/2010  11:29 AM    <DIR>          .
03/18/2010  11:29 AM    <DIR>          ..
12/18/2009  12:50 PM             5,010 Devquery.c
03/18/2010  11:29 AM            13,824 Devquery.exe
03/18/2010  11:29 AM               616 Devquery.exe.manifest
03/18/2010  11:29 AM             2,378 Devquery.obj
03/12/2010  10:59 AM             4,886 ReadMe-2.txt
12/18/2009  12:50 PM             3,040 ReadMe.txt
               6 File(s)         29,754 bytes
               2 Dir(s)  173,155,835,904 bytes free

C:\Documents and Settings\All Users\Documents\National Instruments\NI-488.2\Examples\Standard C\Devquery>echo %NIEXTCCOMPILERSUPP%
C:\Program Files\National Instruments\Shared\ExternalCompilerSupport\C\

C:\Documents and Settings\All Users\Documents\National Instruments\NI-488.2\Examples\Standard C\Devquery>

 

 

0 Kudos
Message 6 of 17
(8,589 Views)
Solution
Accepted by topic author chrissssssss

Wow it is working now!

 

I used c code things like:

 

#include "ni4882.h"

Dev = ibdev(BDINDEX, PRIMARY_ADDR_OF_DMM, NO_SECONDARY_ADDR,

TIMEOUT, EOTMODE, EOSMODE);

ibclr(Dev);  ibwrt(Dev, Msg, WrtBufLen); ibrd(Dev, Abyte, 1); 

ibonl(Dev, 0);

(for the ni4882.h) 

C:\Program Files\National Instruments\Shared\ExternalCompilerSupport\C\include

"C:\Program Files\National Instruments\Shared\ExternalCompilerSupport\C\lib32\msvc\ni4482.obj"

 

MSVC include dir needs to go into Project|Properties|Config Prop|C/C++|General|Additional include directories

MSVC obj file needs to go into Project|Properties|Linker|input|Additional dependencies USE QUOTED STRING !

 

 

Thanks for our help!

0 Kudos
Message 7 of 17
(8,578 Views)
Glad to hear it helped, Chris!
Warm regards,

pBerg
0 Kudos
Message 8 of 17
(8,560 Views)

Hey Chris,

 

Are you using VC++ 6.0 for this one? Also what is the version of 4882 s/w are you using? 2.6/2.2 or some else? I think I am in same boat as you were. I want to compile one sample example and move on with my other fancy stuff.... Any suggestions would be welcome. I have to use 6.0 VC++ and I am having issues as it cant read gpib-32.obj. I have the Dirs in include dir and options for compiling all in right place...

 

thanks

-M.

0 Kudos
Message 9 of 17
(7,918 Views)

Hi M-,

 

Looks like I have 2.7.3 from National Instruments.  I got the free Microsoft VC++ they call "Microsoft Visucal C++ 2008 Express Edition". 

 

Also, from my notes about VC++ Programming...


HINTS:
------
1. Create new project using:  WIN32/WIN32 Console APP
    App Settings: Console App & Empty Proj
2. Point to Library for ni4882.h; Project|Config prop|C/C++|General|ADDITIONAL INCLUDE DIR
 C:\Program Files\National Instruments\Shared\ExternalCompilerSupport\C\include
3. Point to object ni4882.obj file; Project|Properties|Linker|Input|ADDITIONAL DEPENDENCIES
 "C:\Program Files\National Instruments\Shared\ExternalCompilerSupport\C\lib32\msvc\ni4882.obj"

 

 

Good luck.

...Chris

0 Kudos
Message 10 of 17
(7,841 Views)