Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

c++ - Building ZXing (Zebra Crossing) Library on Linux

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

At least we got it here working in some way. Instead of using the hand made Makefile, a collegue gave me a cmake input file:

project(zxtest)
cmake_minimum_required(VERSION 3.16)

set (CMAKE_CXX_STANDARD 11)

add_executable (zxtest zxtest.cpp)

include_directories(/usr/local/include/ZXing)

target_link_libraries (zxtest ZXing)

Then we created the Makefile using cmake and this input file. The resulting Makefile is over 5K big. But that works. We still do not know why resp. why it does not work with the hand made Makefile. So the bug is somehow in the Makefile provided in the question above.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...