26 March 2011

Configure NetBeans to Statically Link MinGW C & C++ Libraries

Installed MinGW g++ 4.5.2 and got the following Windows error when trying to run a C++ program I just compiled: The program can't start because libgcc_s_dw2-1.dll is missing from your computer. After fixing that error, Windows displayed a similar message regarding libstdc++-6.dll. Basically, g++ doesn not statically link the C and C++ standard libraries with an executable by default.

  • In Windows, copy the required library files, libgcc_s_dw2-1.dll and libstdc++-6.dll from the MinGW bin folder into the same folder as the executable or add the MinGW bin folder into the PATH environment variable.
  • If using NetBeans 6.9, configure the project properties to statically link the libraries to the executable:
    1. Select menu item File, Project Properties.
    2. In the Project Properties dialog, expand node Build, Linker.
    3. In Command Line, set Additional Options = -static-libgcc -static-libstdc++

05 March 2011

Leading Semicolon Comments a Line in CMD FOR /F

I wondered why the following CMD script was not processing some lines ...

for /f %a in (test.txt) do @echo %a

... with this sort of test where the semicolon is a field separator. All the lines were processed when the field separator is a space, tab or comma.


When I ran the script, the echo command is only called for the first line. It turns out that, by default, for /f regards any line starting with a semicolon to be a comment and ignores it. It's similar to using:

for /f "eol=;" %a in (test.txt) do @echo %a

Note that the Microsoft documentation doesn't state the default for the eol keyword.

See Also