0

Headers are included but static library (influxdb) is not.

My tasks.json file:

{
"tasks": [
    {
        "type": "shell",
        "label": "g++.exe build active file (mt)",
        "command": "C:/msys64/mingw64/bin/g++.exe",
        "args": [
            "-v",
            "-LC:/influxdb-cxx/lib",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "-std=c++17",
            "-lws2_32",
            "-lInfluxDB"
        ],
        "options": {
            "cwd": "C:/msys64/mingw64/bin"
        },
        "problemMatcher": [
            "$gcc"
        ]
    },
    {
        "type": "shell",
        "label": "g++.exe build active file",
        "command": "C:/msys64/mingw64/bin/g++.exe",
        "args": [
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "-std=c++17"
        ],
        "options": {
            "cwd": "C:/msys64/mingw64/bin"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build"
    }
],
"version": "2.0.0"
}

Using -v option shows that library path and library name are passed to the linker (-LC:/influxdb-cxx/lib and -lInfluxDB):

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/collect2.exe -plugin C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/liblto_plugin-0.dll -plugin-opt=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/lto-wrapper.exe -plugin-opt=-fresolution=C:\Users\Admin\AppData\Local\Temp\ccxBryht.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -m i386pep -Bdynamic -o c:/path/to/executable.exe C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/crtbegin.o -LC:/influxdb-cxx/lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0 -LC:/msys64/mingw64/bin/../lib/gcc -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../.. C:\Users\Admin\AppData\Local\Temp\ccjciO8C.o -lws2_32 -lInfluxDB -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/default-manifest.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/

On compilation, I get "undefined reference" error on all functions from this library. But linker doesn't say that file is not found so it links the library, I guess. This library file contains all functions. I have checked this using nm.

I have also tried to change linkage order but it didn't help.

My system is Windows 7, editor is VS code, compiler is msys2 mingw64 g++.

Library path is included in LIB environment variable, headers path is included in INCLUDE and dll path is included in Path.

1 Answers1

0

Add an an additional reference to -lInfluxDB should be the end of the command line. I don't know how to do this in tasks.json.

I believe the GNU linker only forward resolves dependencies. That is if library A depends on B, then -lA must appear before -lB in the command line order. If both A and B dependon each other, you can do -lA -lB -lA or read this.

selbie
  • 82,148
  • 13
  • 83
  • 154