1

When I try to build my code in Visual Studio code with MinGW, I get a linker error. I am currently reading the graphics chapters from Bjarne Stroustrup's "Principles and Practice Using C++, 2nd edition" and trying to get the necessary files to work. I managed to get FLTK to work, but as soon as I added Stroustrup's files two errors appeared when trying to build. I am currently on Windows 10 x64-based system and using the latest version of MinGW, FLTK and Visual Studio code. I have spent the past days trying to get this to work, as you see my tasks.json is a bit messy.

The error message:

c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/MinGW/msys/1.0/local/lib/libfltk_images.a(Fl_JPEG_Image.o):Fl_JPEG_Image.cxx:(.text$_ZN13Fl_JPEG_ImageC2EPKcPKh+0x343): undefined reference to `Fl_Shared_Image::Fl_Shared_Image(char const*, Fl_Image*)'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:/MinGW/msys/1.0/local/lib/libfltk_images.a(Fl_JPEG_Image.o):Fl_JPEG_Image.cxx (.text$_ZN13Fl_JPEG_ImageC2EPKcPKh+0x34d): undefined reference to `Fl_Shared_Image::add()'

main.cpp

#include "Simple_window.h"
#include "Graph.h"
int main() {
    Point tl{100,100};

    Simple_window win{tl,600,400,"Canvas"};

    Graph_lib::Polygon poly;

    poly.add(Point{300,200});
    poly.add(Point{350,100});
    poly.add(Point{400,200});

    poly.set_color(Color::red);

    win.attach(poly);

    win.wait_for_button();
}

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:/MinGW/msys/1.0/local/include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\MinGW\\bin\\g++.exe",
            "cStandard": "c11",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "clang-x86"
        }
    ],
    "version": 4
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "shell: g++.exe build active file",
            "command": "C:\\MinGW\\bin\\g++.exe",
            "args": [
                "-g",
                "${fileDirname}\\*.cpp",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "-LC:/MinGW/msys/1.0/local/lib",
                "-IC:/MinGW/msys/1.0/local/include",
                "-mwindows",
                "-lfltk",
                "-lfltk_images",
                "-lfltk_jpeg",
                "-lole32",
                "-luuid",
                "-lcomctl32",
            ],
            "options": {
                "cwd": "C:\\MinGW\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}
  • Sounds like you're not using the right version of FLTK, or those member functions reside in another library file. – underscore_d May 28 '20 at 10:35
  • I am currently using the latest version of LFTK (1.3.5), however, Bjarne uses 1.1.x, do you think I should use 1.1 instead? @underscore_d –  May 28 '20 at 10:37
  • That sounds worth trying if it's doable for you. However, assuming somewhat standard versioning, I would not expect a 1.x release to remove symbols. – underscore_d May 28 '20 at 10:38
  • Alright, I will give it a shot! Thank you for your quick response. –  May 28 '20 at 10:39

0 Answers0