jbeder / yaml-cpp

A YAML parser and emitter in C++
MIT License
4.91k stars 1.77k forks source link

Problems with absend symbols in static library on Windows #1284

Closed d7dsem closed 1 month ago

d7dsem commented 1 month ago

Hi I am try create static library for Windows x64 to use in my nown project I did next steps: Clone repo prepare build dir

mkdir build
cd build

Configure Cmake in different variants: 1) cmake -G "MinGW Makefiles" -DYAML_BUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=../for_D7 .. 2) cmake -G "MinGW Makefiles" -DYAML_BUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=../for_D7 -DYAML_CPP_BUILD_CONTRIB=ON -DYAML_CPP_BUILD_TOOLS=ON -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_FLAGS="-std=c++17" .. Execute building cmake --build . --config Release --target install

And and same shit for using MSVC

I`v got for one case yaml-cpp.lib (when i try ti get it with MSVC) andd libyaml-cpp.a (for MinGW)

I try to use both of them in my app. This is how in my main.cpp:

if (argc == 2 && (strstr(argv[1], ".yaml") != NULL)) {
        char* file_folder;
        char* file_name;
        char* mode;
        char* dll_folder;
        char* dll_name;
        int chunk_len;
        int port;

        try {
            YAML::Node config = YAML::LoadFile(argv[1]);
            if (config["sample_source"]) {
                YAML::Node sample_source = config["sample_source"];
                if (sample_source["file_folder_env_var"]) {
                    const char* ts = sample_source["file_folder_env_var"].as<std::string>().c_str();
                    file_folder = get_env_variable(ts);
                    if (file_folder == NULL) {
                        file_folder = (char*)DEFAULT_SIGNAL_DATA_PATH;
                    }
                } else {
                    file_folder = (char*)"NOT SET";
                }

                if (sample_source["file_name"]) {
                    file_name = (char*)sample_source["file_name"].as<std::string>().c_str();
                } else {
                    file_name = (char*)"NOT SET";
                }

                if (sample_source["mode"]) {
                    mode = (char*)sample_source["mode"].as<std::string>().c_str();
                } else {
                    mode = (char*)"NOT SET";
                }

                if (sample_source["rtlsdr_dll"]["path"]) {
                    dll_folder = (char*)sample_source["rtlsdr_dll"]["path"].as<std::string>().c_str();
                } else {
                    dll_folder = (char*)"NOT SET";
                }

                if (sample_source["rtlsdr_dll"]["file"]) {
                    dll_name = (char*)sample_source["rtlsdr_dll"]["file"].as<std::string>().c_str();
                } else {
                    dll_name = (char*)"NOT SET";
                }

                if (sample_source["port"]) {
                    port = sample_source["port"].as<int>();
                } else {
                    port = -1;
                }

                if (sample_source["chunk_len"]) {
                    chunk_len = sample_source["chunk_len"].as<int>();
                } else {
                    chunk_len = -1;
                }

                printf("Mode: %s\n", mode);
                printf("File path: %s\n", file_folder);
                printf("File name: %s\n", file_name);
                printf("DLL path: %s\n", dll_folder);
                printf("DLL name: %s\n", dll_name);
                printf("Port: %d\n", port);
                printf("Chunk len: %d\n", chunk_len);
            }
        } 
        catch (const std::exception& ex) {
            printf("Error: %s\n", ex.what());
            return -1;
        }
        return 0;
    }
My app compiled - i get object files. Compile in that way:

`gcc -c -g -D_DEBUG -D_D7 -std=c++17 -Iexternal_binaries\yaml-cpp\include -Iexternal_binaries\ffftw3.3.5_x64 -Iinclude src\rtl-sdr-wrapper\wrapper.cpp src\rtl-sdr-wrapper\rcv_test.cpp src\common.cpp src\main.cpp`

But linkage fails

`g++ -o build/release/spectro_mk2.exe wrapper.o rcv_test.o common.o main.o -L"external_binaries\yaml-cpp\lib" -L"external_binaries\ffftw3.3.5_x64" -lyaml -llibfftw3-3 -lws2_32`

Output is too large but in breef It couldnt find some symbols. I make check like this
nm libyaml-cpp.a > symbols.txt
findstr "__imp__ZN4YAML8LoadFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE" symbols.txt
findstr "__imp__ZTVN4YAML9ExceptionE" symbols.txt
findstr "__imp__ZN4YAML6detail6memory11create_nodeEv" symbols.txt
findstr "__imp__ZN4YAML11InvalidNodeD1Ev" symbols.txt
findstr "__imp__ZN4YAML23RepresentationExceptionE" symbols.txt
findstr "__imp__ZN4YAML13BadConversionE" symbols.txt
findstr "__imp__ZN4YAML6detail9node_data12empty_scalarB5cxx11Ev" symbols.txt
findstr "__imp__ZN4YAML12BadSubscriptE" symbols.txt
findstr "__imp__ZN4YAML6detail13memory_holder5mergeERS1_" symbols.txt

No such symbols Same trouble when i try use static library made by MSVC - same linker errors

jbeder commented 1 month ago

Stack Overflow?

d7dsem commented 3 weeks ago

Stack Overflow what for? This is the resource of that proj? who knows WTF is going on better then developers?

d7dsem commented 3 weeks ago

Can we hsve some chat? Iam new one for al this Git-Hub stuff. Fnd wil be grateful for your time))

jbeder commented 3 weeks ago

I'm the only developer and I have no time. This looks like a general problem, not a problem with the library. The community on SO can help figure that out. If it turns out to be a problem with the library, then you can file a bug.

d7dsem commented 3 weeks ago

I can't categorize that problem. Looks like not all staff get to build lib. In any case thanks

ср, 5 черв. 2024 р., 16:01 користувач Jesse Beder @.***> пише:

I'm the only developer and I have no time. This looks like a general problem, not a problem with the library. The community on SO can help figure that out. If it turns out to be a problem with the library, then you can file a bug.

— Reply to this email directly, view it on GitHub https://github.com/jbeder/yaml-cpp/issues/1284#issuecomment-2149815990, or unsubscribe https://github.com/notifications/unsubscribe-auth/A4XW337NT3OEOEYQ6C2DZTLZF4D3FAVCNFSM6AAAAABISW7736VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBZHAYTKOJZGA . You are receiving this because you authored the thread.Message ID: @.***>