[Linker error] undefined reference to...

I'm modifying a program to collect data from a National Instruments spectrum analyzer. For correspondence with this piece of equipment, the reference to header file #include <ni488.h> is written into the program. The program was working fine before, but after I saved the updated program to my flash drive and another location where it needed to be, I started receiving these errors upon compilation:

1
2
3
4
[Linker error]undefined reference to 'ibdev@24'
[Linker error]undefined reference to 'ibwrt@12'
[Linker error]undefined reference to 'ibrd@12'
[Linker error]undefined reference to 'ibcntl'


and a host of other undefined references to functions defined in the header file mentioned above.

The ni488 header file is included in the folder with the program in each location where it was saved. Why is it now having trouble locating this header and what can I do to fix it? I've tried resaving the file and using Execute >> Rebuild All, but nothing seems to work.
You have to include in your project the corresponding library where these symbols are defined.
To build on Vlad's answer, note that these are all linker errors. Linking happens after compilation; your code compiles fine. The problem is not in your code.
As I mentioned in the first paragraph,

#include<ni488.h>

is included in the program and contains all of these functions. In fact, if I look at the "Classes" tab on the left side of the screen, all of these functions are included under the list of classes. Furthermore, when I click on one of these functions the ni488 header tab appears next to the main source file tab.

For some reason, though, the program does not recognize these functions when it compiles.
After reading Moschops's reply I looked at the error message again. The last two lines read:

1
2
Id returned 1 exit status
[Build error][RF-DFS.exe] Error 1


And prior to the second line, it gives the address for a Makefile.win file associated with the program. This must be why, for the other locations where it is saved, every time I attempt to compile, I get this error screen:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Project: Project1
# Makefile created by Dev-C++ 4.9.9.2

CPP  = g++.exe
CC   = gcc.exe
WINDRES = windres.exe
RES  = RF-DFS_private.res
OBJ  = "Y:/coopshare/Harter/RF-DFS/RF-DFS\ (Frentzel-Harter)\ -\ Final/RF-DFS.o" $(RES)
LINKOBJ  = "Y:/coopshare/Harter/RF-DFS/RF-DFS (Frentzel-Harter) - Final/RF-DFS.o" $(RES)
LIBS =  -L"C:/Dev-Cpp/lib" gpib-32.obj  
INCS =  -I"C:/Dev-Cpp/include" 
CXXINCS =  -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include" 
BIN  = RF-DFS.exe
CXXFLAGS = $(CXXINCS)  
CFLAGS = $(INCS)  
RM = rm -f

.PHONY: all all-before all-after clean clean-custom

all: all-before RF-DFS.exe all-after


clean: clean-custom
	${RM} $(OBJ) $(BIN)

$(BIN): $(OBJ)
	$(CPP) $(LINKOBJ) -o "RF-DFS.exe" $(LIBS)

"Y:/coopshare/Harter/RF-DFS/RF-DFS\ (Frentzel-Harter)\ -\ Final/RF-DFS.o": Y:/coopshare/Harter/RF-DFS/RF-DFS\ (Frentzel-Harter)\ -\ Final/RF-DFS.cpp
	$(CPP) -c "Y:/coopshare/Harter/RF-DFS/RF-DFS (Frentzel-Harter) - Final/RF-DFS.cpp" -o "Y:/coopshare/Harter/RF-DFS/RF-DFS (Frentzel-Harter) - Final/RF-DFS.o" $(CXXFLAGS)

RF-DFS_private.res: RF-DFS_private.rc 
	$(WINDRES) -i RF-DFS_private.rc --input-format=rc -o RF-DFS_private.res -O coff 


with an error that reads

[Build error]***multiple target patterns. Stop

Does anybody know what this means? Could it have something to do with trying to save the same a program and associated files in multiple locations?
For some reason, though, the program does not recognize these functions when it compiles.


That is incorrect. You are not having compilation errors. You are having linker errors.

As I mentioned in the first paragraph,

#include<ni488.h>

is included in the program and contains all of these functions.

No, it does not. If it did, you would not be having those linker errors. It must contain declarations of those functions. This allows the compiler to ensure that you are using the functions correctly. It effectively leaves a note to the linker saying "here, please call the actual code that does the actual work for this function". The linker then goes looking through all the binary objects it has been told to look through, which will be your code and any libraries it has been told to look through. If it cannot find the actual (compiled) code that does the actual work, it comes back with the complaint "undefined reference".

That is what is happening here. Your code is compiling. You have not told the linker where to find the actual compiled code for these library functions.
The line that is highlighted with an "x" beside it is the one labeled 26 above, the one that reads

$(BIN): $(OBJ)
As an aside, that's a terrible choice of IDE that comes with a decade old compiler, both of which have many bugs.
Do you have one of the following file on your hard drive?

gpib-32.obj ni4882.obj
Well like I said, I'm modifying someone else's old program that was written several years ago, and I don't have time to write a new one. I'm working with what I've got.

Do you have any ideas on why the program would have been able to find the code for the functions before, but not now?
Yes, I have both of those.
Do you have any ideas on why the program would have been able to find the code for the functions before, but not now?

If it has been moved, or if the search path that it was on changed it will no longer be able to find it, and probably lots of other potential reasons.

One of those is the library you need. The documentation for the library should tell you. You need to tell your IDE the name of it, and the location.
Last edited on
Wonderful. I can do that. Would this be written into the source code?

Looking in the header file, I see this text early on:

extern "C"

Would this be a reference to the libraries mentioned above that I need to update, as in extern "C:\Program Files\National Instruments..."?
Last edited on
No, it is not something for the source code (except in the abomination of recent version of Microsoft's Visual C++, but that's not relevant here). It is an instruction that gets passed to the linker, which is a separate executable program. Somewhere in your IDE is an option to tell it the library name, and the directory path the library is on.
Last edited on
No, MinGW does not support this, unlike Visual Studio.
You need to find "Linker settings" in your IDE and add all the needed libraries here, then rebuild.
extern "C"

Would this be a reference to the libraries mentioned above that I need to update, as in extern "C:\Program Files\National Instruments..."?


No. The extern directive is part of the C++ programming language and has nothing to do with search paths.
I found the Linker settings and updated the library. I'm not getting the "undefined reference" notifications anymore. Thanks.

I'm still getting the "multiple target patterns" problem, though. Not sure what the origin of that is. From what I've read, it has something to do with third-party libraries and possible errors in directory names.

I'll read some more on it and try to see if I can untangle it.
Last edited on
Topic archived. No new replies allowed.