1

My Case is as follows: I made a GUI program (wxWidgets based) on Microsoft Visual Studio where this code was running fine mixing both C++ and C files, basically the C files do very little things but I can't discard them cause I am very beginner with C++ OOP - I have OOP background from Java which I feel far different than C++ - but I can deal with it to certain extent. Anyway, the program was running fine on Visual Studio 2019 but when I place it on another computer with no Visual Studio installation, it start firing missing .dlls after little research I found this is due to the lack of Visual Studio installation on that computer and I don't have admin rights to install these .dll files. I looked for rebuilding the files on VS Code, I used the g++ compiler so I needed to configure wxWidgets with MinGw compiler. I managed to make the Hello World code on wxWidgets work. When I ran my code it didn't work after a little bit of struggle I eliminated any errors, however when I built the code for Debug/Release this what it get on the terminal:

C:\Users<USER>\AppData\Local\Temp\ccUB3ReN.o: In function ZN5cMainC2Ev: C:/Users//Desktop/wxTest/src/cMain.cpp:13: undefined reference to Bus_Construct C:/Users//Desktop/wxTest/src/cMain.cpp:13: undefined reference to Decker_Construct C:\Users<USER>\AppData\Local\Temp\ccUB3ReN.o: In function ZN5cMain16CalculateClickedER14wxCommandEvent: C:/Users//Desktop/wxTest/src/cMain.cpp:426: undefined reference to getCG C:/Users//Desktop/wxTest/src/cMain.cpp:442: undefined reference to getCGz C:/Users//Desktop/wxTest/src/cMain.cpp:454: undefined reference to getPassCGX C:/Users//Desktop/wxTest/src/cMain.cpp:455: undefined reference to getPassCGY C:/Users//Desktop/wxTest/src/cMain.cpp:456: undefined reference to getPassCGZ C:/Users//Desktop/wxTest/src/cMain.cpp:457: undefined reference to totalCG C:/Users//Desktop/wxTest/src/cMain.cpp:470: undefined reference to delay C:/Users//Desktop/wxTest/src/cMain.cpp:528: undefined reference to freeSeats C:/Users//Desktop/wxTest/src/cMain.cpp:530: undefined reference to freeSingleDecker C:\Users<USER>\AppData\Local\Temp\ccUB3ReN.o: In function ZN5cMain19GenerateGroupsClickER14wxCommandEvent: C:/Users//Desktop/wxTest/src/cMain.cpp:622: undefined reference to initSingleDecker C:/Users//Desktop/wxTest/src/cMain.cpp:627: undefined reference to initSeats collect2.exe: error: ld returned 1 exit status The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command C:<USER>\Softwares\MinGW\mingw32\bin\g++.exe -g C:\Users<USER>\Desktop\wxTest\src*.cpp C:\Users<USER>\Desktop\wxTest\src*.c -o C:\Users<USER>\Desktop\wxTest\build\debug\cApp.exe -I C:\Users<USER>\Desktop\wxTest\include -I C:\wx\wxWidgets-3.1.5\include -I C:\wx\wxWidgets-3.1.5\lib\gcc_dll\mswud -L C:\wx\wxWidgets-3.1.5\lib\gcc_dll -l wxmsw31ud_core -l wxbase31ud" terminated with exit code: 1

What I noticed is some mangled name with ZN5cMainC2Ev which originally a class name cMain. I think the trick is at the task.json arguments:

{
"version": "2.0.0",
"tasks": [
    {
        "type": "shell",
        "label": "Debug",
        "command": "C:\\Amir\\Softwares\\MinGW\\mingw32\\bin\\g++.exe",
        "args": [
            "-g",
            "${workspaceFolder}\\src\\*.cpp",
            "-o",
            "${workspaceFolder}\\build\\debug\\${fileBasenameNoExtension}.exe",
            "-I",
            "${workspaceFolder}\\include",
            "-I",
            "C:\\wx\\wxWidgets-3.1.5\\include",
            "-I",
            "C:\\wx\\wxWidgets-3.1.5\\lib\\gcc_dll\\mswud",
            "-L",
            "C:\\wx\\wxWidgets-3.1.5\\lib\\gcc_dll",
            "-l",
            "wxmsw31ud_core",
            "-l",
            "wxbase31ud",
        ],
        "options": {
            "cwd": "${workspaceFolder}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build",
        "detail": "compiler: C:\\Amir\\Softwares\\MinGW\\mingw32\\bin\\g++.exe"
    },
    {
        "type": "shell",
        "label": "Release",
        "command": "C:\\Amir\\Softwares\\MinGW\\mingw32\\bin\\g++.exe",
        "args": [
            "${workspaceFolder}\\src\\*.cpp",
            "${workspaceFolder}\\src\\BusCalcs.c",
            "${workspaceFolder}\\src\\CG_Engine.c",
            "${workspaceFolder}\\src\\Helper.c",
            "-o",
            "${workspaceFolder}\\build\\release\\${fileBasenameNoExtension}.exe",
            "-I",
            "${workspaceFolder}\\include",
            "-I",
            "C:\\wx\\wxWidgets-3.1.5\\include",
            "-I",
            "C:\\wx\\wxWidgets-3.1.5\\lib\\gcc_dll\\mswu",
            "-L",
            "C:\\wx\\wxWidgets-3.1.5\\lib\\gcc_dll",
            "-l",
            "wxmsw31u_core",
            "-l",
            "wxbase31u",
        ],
        "options": {
            "cwd": "${workspaceFolder}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build",
        "detail": "compiler: C:\\Amir\\Softwares\\MinGW\\mingw32\\bin\\g++.exe"
    }
]

}

  • 1
    Did you use [`extern "C"`](https://stackoverflow.com/q/1041866/10077) on the C++ declarations of the C bits? – Fred Larson Dec 02 '21 at 20:50
  • 1
    "the C files do very little things but I can't discard them cause I am very beginner with C++ OOP" -- Do you understand that you don't *have* to use OOP in C++? – Fred Larson Dec 02 '21 at 20:52
  • Do not compile C source files with a C++ compiler (such as g++), which you appear to have configured your project to do. At least in Release mode. In Debug mode, you seem to be compiling a smaller set of files. Compile C with a C compiler (gcc) and C++ with a C++ compiler. – John Bollinger Dec 02 '21 at 20:59
  • @FredLarson yes the .h C files are inside an extern "C" scope/block – DesertXGhost Dec 02 '21 at 23:27
  • @JohnBollinger I am totally new to "make" files or in other words these compilers and linkers configuration files/scripts. So what to write in the task.json to compile these C files with the gcc compiler away from the g++ and would they be all linked together into 1 .exe file? by the way I want all cpp and c files are all compiled and linked together at the end of the day for both Debug and Release – DesertXGhost Dec 02 '21 at 23:31

1 Answers1

0

The problem was solved by renaming the .C files to .CPP files it build correctly for both Debug and Release and my App was working correctly however when I ran it on another computer I got loads of missing .dlls more than I used to get from VS2019 build I think my problem is now handling how to optimize my installation of the application on any computer.

Thanks All.