I'm currently struggling to get started with ZXing. So i downloaded the source, updated cmake to the required version, installed gcc 9 and tried to compile it using cmake. I did not succeed using the CMakeLists.txt in the root directory, but i succeeded in building the lib using the CMakeLists.txt in the core directory. The result was a libZXing.a, which i installed using the make install target. The lib was installed into /usr/local/lib. So far so good.
Now i try to build a very simple program, just to test, if building was successful.
#include "BarcodeFormat.h"
#include <iostream>
#include <string>
using namespace ZXing;
std::ostream& operator<<(std::ostream& os, BarcodeFormat bf) {
os << ToString(bf);
return os;
}
int main(int argc, char **argv) {
for (auto f : BarcodeFormats::all()) {
std::cout << f << std::endl;
}
return 0;
}
Compiling works, linking does not work: Undefined reference to BarcodeFormat::ToString(BarcodeFormat). So it seems to be not in the library. I compiled the BarcodeFormat.cpp in the core/src directory separately, copied the object file to my project directory, linked it, and that worked. I got a working executable.
So i assume i did something wrong while building the library. Any idea what could go wrong here? Of cource i added the necessary -I, -L and -l flags to the compile. The Makefile:
CC := g++
CCFLAGS := -std=c++17 -I/home/cnc/prj/zxing-cpp-master/core/src
LDFLAGS := -L/usr/local/lib -lZXing
all: zxtest
zxtest: zxtest.o BarcodeFormat.o
${CC} -o $@ ${LDFLAGS} $^
zxtest.o: zxtest.cpp
${CC} -c ${CCFLAGS} -o $@ $<
BarcodeFormat.o: ../zxing-cpp-master/core/src/BarcodeFormat.cpp
${CC} -c ${CCFLAGS} -o $@ $<
Without that extra BarcodeFormat file it does not link
I'm quite old, so i do know C and basic C++. I'm not up to date with the new C++ features.
PS: Sorry, i forgot: This is about the ZXing c++ port (obviously, since the example is c++): https://github.com/nu-book/zxing-cpp
question from:
https://stackoverflow.com/questions/66059595/building-zxing-zebra-crossing-library-on-linux 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…