LeanCreator icon indicating copy to clipboard operation
LeanCreator copied to clipboard

BUSY Hello World project template

Open ghost opened this issue 2 years ago • 5 comments

This the the BUSY build script:

let config : Config {
    if (target_os == `linux) || (target_os == `macos) {
        .lib_names += [ "m" "stdc++" ]
        .ldflags += "-shared-libgcc"
    }else if target_os == `win32 {
        .lib_names = [ "Gdi32" "User32" "Shell32" "Comdlg32" ]
    }else {
        error("target os not supported")
    }
}

let hello ! : Executable {
    .sources += ./main.cpp
    .configs += config
}

First problem: on Compile Output tab, I found gcc is invoked instead of g++. Why? The project is obviously C++.

Second problem: it's obviously a command line program. Why do you tell it to link with "Gdi32" "User32" "Shell32" "Comdlg32" but not libstdc++? It's definitely not a Windows API GUI application! The result is the program failed to link because missing of symbols from libstdc++. Replace "Gdi32" "User32" "Shell32" "Comdlg32" with "stdc++" then the program could be linked without problems. But why don't use g++ from the beginning? g++ will link with libstdc++ automatically.

ghost avatar Jun 14 '23 14:06 ghost

I found gcc is invoked instead of g++

Doesn't matter as long as you don't use exotic extensions for C++ files; gcc is just a generic alias for all GCC compilers; see e.g. https://stackoverflow.com/questions/172587/what-is-the-difference-between-g-and-gcc

it's obviously a command line program. Why do you tell it to link with "Gdi32" "User32" "Shell32" "Comdlg32" but not libstdc++?

This is just a generic template so the executable is likely to compile on each platform. It's not set in stone; I can change it or add another one.

rochus-keller avatar Jun 14 '23 14:06 rochus-keller

The problem is when you are using gcc, you need to explicitly tell it to link with libstdc++, which you don't on Windows and resulted in linking errors. These libraries, "Gdi32" "User32" "Shell32" "Comdlg32", are not needed unless you are developing Windows API GUI application, even Windows API command line application doesn't need them.

ghost avatar Jun 14 '23 14:06 ghost

I just tried again on my Windows 11 machine where LeanCreator uses the default desktop profile with the auto detected VC14 toolchain, which worked; I rarely use GCC on Windows, and linking VC with stdc++ gives an error; but as it seems I should rather check the target_toolchain instead of the target_os; I just copied the Windows libraries over from the Qt Core (non-gui) spec without a lot of thoughts.

I will change the template to something like:

    QString text =
            "let config : Config {\n"
            "    if (target_toolchain == `gcc) {\n"
            "        .lib_names += [ \"m\" \"stdc++\" ]\n"
            "        .ldflags += \"-shared-libgcc\"\n"
            "    }else if target_target_toolchain == `msvc {\n"
            "    }else {\n"
            "        error(\"target toolchain not supported\")\n"
            "    }\n"
            "}\n\n";

You're invited to propose alternatives.

rochus-keller avatar Jun 14 '23 14:06 rochus-keller

Is target_target_toolchain a typo?

ghost avatar Jun 14 '23 16:06 ghost

Oops, yes, too quick with copy/paste, sorry; see http://software.rochus-keller.ch/busy_spec.html for valid global vars.

rochus-keller avatar Jun 14 '23 16:06 rochus-keller