我不想使用大型 IDE,而是想尝试第一次使用 makefile 的经验。在不太了解 makefile 的情况下,我找到了一个示例并尝试将其应用于我的项目。 生成文件如下所示:
#This is an easier to use and modify makefile, but it is slightly more difficult to read than the simple one:
#
# 'make depend' uses makedepend to automatically generate dependencies
# (dependencies are added to end of Makefile)
# 'make' build executable file 'mycc'
# 'make clean' removes all .o and executable files
#
# define the C compiler to use
#CC = gcc
#CC = "C:\MinGW\bin\g++.exe"
CXX = "C:\MinGW\bin\g++.exe"
# define any compile-time flags
#CPPFLAGS = -Wall -g -std=c++11
CXXFLAGS = -Wall -g -std=c++11
# define any directories containing header files other than /usr/include
#
#INCLUDES = -I/home/newhall/include -I../include
INCLUDES = -IC:\Users\k0cke\Desktop\TestMake\ATCCalib\inc
# define library paths in addition to /usr/lib
# if I wanted to include libraries not in /usr/lib I'd specify
# their path using -Lpath, something like:
#LFLAGS = -L/home/newhall/lib -L../lib
LFLAGS = -LC:\Users\k0cke\Desktop\TestMake\ATCCalib\lib
# define any libraries to link into executable:
# if I want to link in libraries (libx.so or libx.a) I use the -llibname
# option, something like (this will link in libmylib.so and libm.so:
#LIBS = -lmylib -lm
LIBS = -lvisa32
# define the C source files
#SRCS = emitter.c error.c init.c lexer.c main.c symbol.c parser.c
SRCS = main.cpp atcFlash.cpp measurements.cpp SerialCommunicationClass.cpp
# define the C object files
#
# This uses Suffix Replacement within a macro:
# $(name:string1=string2)
# For each word in 'name' replace 'string1' with 'string2'
# Below we are replacing the suffix .c of all words in the macro SRCS
# with the .o suffix
#
OBJS = $(SRCS:.c=.o)
# define the executable file
#MAIN = mycc
MAIN = apdCalib.exe
#
# The following part of the makefile is generic; it can be used to
# build any executable just by changing the definitions above and by
# deleting dependencies appended to the file from 'make depend'
#
.PHONY: depend clean
all: $(MAIN)
@echo Simple compiler named mycc has been compiled
$(MAIN): $(OBJS)
$(CXX) $(CXXFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS) $(LFLAGS) $(LIBS)
# this is a suffix replacement rule for building .o's from .c's
# it uses automatic variables $<: the name of the prerequisite of
# the rule(a .c file) and $@: the name of the target of the rule (a .o file)
# (see the gnu make manual section about automatic variables)
.c.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
clean:
$(RM) *.o *~ $(MAIN)
depend: $(SRCS)
makedepend $(INCLUDES) $^
# DO NOT DELETE THIS LINE -- make depend needs it
我将 mingw 安装到“C\MinGW in”。在文件夹“C:\Users\k0cke\Desktop\TestMake\ATCCalib”中,我有四个 .cpp 源文件和“makefile”。在“C:\ Users \ k0cke \ Desktop \ TestMake \ ATCCalib \ inc”中,我有6个.h文件。 “visa.h”和“visatype.h”是头文件,应该允许我使用 Visa32.lib 的功能。 “C:\Users\k0cke\Desktop\TestMake\ATCCalib\lib”包含库“visa32.lib”。
在 Windows cmd 窗口中,导航到“C:\Users\k0cke\Desktop\TestMake\ATCCalib”并输入 mingw32-make。
现在我收到链接器错误
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\k0cke\AppData\Local\Temp\ccPAAw9m.o:measurements.cpp:(.text+0x10): undefined reference to `viOpenDefaultRM@4'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\k0cke\AppData\Local\Temp\ccPAAw9m.o:measurements.cpp:(.text+0x6d): undefined reference to `viOpen@20'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\k0cke\AppData\Local\Temp\ccPAAw9m.o:measurements.cpp:(.text+0x93): undefined reference to `viGetAttribute@12'
.
.
.
在“measurements.cpp”中,我
#include "measurement.h"
。在“measurement.h”中,我#include "visa.h"
和#include "visatype.h"
您对我可能犯的错误有什么建议吗?我好像没找到什么。
编辑:以下是控制台中显示的构建命令:
"C:\MinGW\bin\g++.exe" -Wall -g -std=c++11 -IC:\Users\k0cke\Desktop\TestMake\ATCCalib\inc -o apdCalib.exe main.cpp atcFlash.cpp measurements.cpp SerialCommunicationClass.cpp -LC:\Users\k0cke\Desktop\TestMake\ATCCalib\lib -lvisa32
atcFlash.cpp: In function 'void atcFlash(serialCommunication&, std::string, std::string, std::string)':
atcFlash.cpp:23:6: warning: unused variable 'chooseSector' [-Wunused-variable]
23 | int chooseSector = 0;
| ^~~~~~~~~~~~
atcFlash.cpp:24:6: warning: unused variable 'validSector' [-Wunused-variable]
24 | int validSector = 0;
| ^~~~~~~~~~~
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\k0cke\AppData\Local\Temp\ccLOPMRY.o: in function `Z9measureACiRdNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE':
C:\Users\k0cke\Desktop\TestMake\ATCCalib/measurements.cpp:12: undefined reference to `viOpenDefaultRM@4'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\k0cke\Desktop\TestMake\ATCCalib/measurements.cpp:21: undefined reference to `viOpen@20'
.
.
超级奇怪的答案:因此,名为“visa32.lib”的库用于与是德科技的测量工具交换命令,例如将其包含到自动测量系统中。我安装了所谓的“Agilent Libraries Suite”。从那里,我获取了库“visa32.lib”。在我尝试过一切之后,我想也许该库已损坏。在我的 PC 上搜索后,我发现 Agilent Libraries Suite 提供了 5 个同名的库。我尝试了其中的每一个,发现其中一个正在工作......所以,我想问题已经解决了。