News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Errors and warnings

Started by Marcel, January 25, 2008, 07:50:41 PM

Previous topic - Next topic

Marcel

I have Errors and warnings with Code::blocks. On MS VC++ 2005 EE everything's fine.
Im not good at speaking English...

-------------- Build: Debug in Timer ---------------

Compiling: main.cpp
C:\C++\Timer\main.cpp: In function `int main()':
C:\C++\Timer\main.cpp:25: warning: statement has no effect
C:\C++\Timer\main.cpp:32: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `1' to `BOOL PlaySoundA(const CHAR*, HINSTANCE__*, DWORD)'
C:\C++\Timer\main.cpp:41: warning: statement has no effect
C:\C++\Timer\main.cpp:50: warning: statement has no effect
C:\C++\Timer\main.cpp:56: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `1' to `BOOL PlaySoundA(const CHAR*, HINSTANCE__*, DWORD)'
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 3 warnings

MortenMacFly

Quote from: Marcel on January 25, 2008, 07:50:41 PM
I have Errors and warnings with Code::blocks. On MS VC++ 2005 EE everything's fine.
You won't get any useful answer with such less information.
What C::B version? What compiler (version)? What OS? What application? Provide code. Provide the compile full log (see my sig)...
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

Marcel

#2
I Use on Windows Code::Blocks with the newest nightly build. My Compiler ist MinGW Version 5.1.3. I used a console aplication.
-------------- Build: Debug in Timer ---------------

mingw32-g++.exe -Wall -fexceptions  -g     -c C:\C++\Timer\main.cpp -o obj\Debug\main.o
C:\C++\Timer\main.cpp: In function `int main()':
C:\C++\Timer\main.cpp:25: warning: statement has no effect
C:\C++\Timer\main.cpp:32: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `1' to `BOOL PlaySoundA(const CHAR*, HINSTANCE__*, DWORD)'
C:\C++\Timer\main.cpp:41: warning: statement has no effect
C:\C++\Timer\main.cpp:50: warning: statement has no effect
C:\C++\Timer\main.cpp:56: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `1' to `BOOL PlaySoundA(const CHAR*, HINSTANCE__*, DWORD)'
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 3 warnings


My Code:
#include <iostream>
#include <windows.h>
using namespace std;

int main()
{
int Auswahl;
int Zeit;

do
{
cout << "1 für Sekunden" << endl;
cout << "2 für Minuten" << endl;
cout << "3 Hilfe" << endl;
cout << "4 um zu Beenden" << endl;
cin >> Auswahl;
cout << endl;

switch (Auswahl)
{
case (1):
{
cout << "Gib die Zeit in Sekunden ein: ";
cin >> Zeit;
for (Zeit; Zeit > 1; Zeit--)
{
cout << "Noch " << Zeit << " Sekunden" << endl;
Sleep (1000);
}
if (Zeit == 1)
cout << "Noch " << Zeit << " Sekunde" << endl;
PlaySound (L"C:\\WINDOWS\\Media\\notify.wav", NULL, SND_SYNC);
cout << "Zeit ist abgelaufen" << endl << endl;
} break;
case (2):
{
cout << "Gib die Zeit in Minuten ein: ";
cin >> Zeit;
if (Zeit > 1)
{
for (Zeit; Zeit >= 1; Zeit--)
{
cout << "Noch " << Zeit << " Minuten" << endl;
Sleep (60000);
}
}
PlaySound (L"C:\\WINDOWS\\Media\\notify.wav", NULL, SND_SYNC);
cout << "Zeit ist abgelaufen" << endl << endl;
} break;
case (3):
{
cout << "Das ist ein Programm, der die Zeit bis zum Ablaufen der Zeit zählt. Wenn die Zeit abgelaufen ist benachrichtigt das Programm sie mit einem Ton." << endl;
cout << endl;
} break;
default:
cout << "Falsche Eingabe!" << endl;
}
} while (Auswahl != 4);
return 0;
}


polygon7

Quote from: Marcel on January 25, 2008, 08:46:17 PM
I Use on Windows Code::Blocks RC2 with the newest nightly build. My Compiler ist MinGW Version 5.1.3. I used a console aplication.
-------------- Build: Debug in Timer ---------------

mingw32-g++.exe -Wall -fexceptions  -g     -c C:\C++\Timer\main.cpp -o obj\Debug\main.o
C:\C++\Timer\main.cpp: In function `int main()':
C:\C++\Timer\main.cpp:25: warning: statement has no effect
C:\C++\Timer\main.cpp:32: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `1' to `BOOL PlaySoundA(const CHAR*, HINSTANCE__*, DWORD)'
C:\C++\Timer\main.cpp:41: warning: statement has no effect
C:\C++\Timer\main.cpp:50: warning: statement has no effect
C:\C++\Timer\main.cpp:56: error: cannot convert `const wchar_t*' to `const CHAR*' for argument `1' to `BOOL PlaySoundA(const CHAR*, HINSTANCE__*, DWORD)'
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 3 warnings


My Code:

PlaySound (L"C:\\WINDOWS\\Media\\notify.wav", NULL, SND_SYNC);
PlaySound (L"C:\\WINDOWS\\Media\\notify.wav", NULL, SND_SYNC);



Hi,
remove "L" from all strings in PlaySound (...) calls.

P.S. Also I think that code

for (Zeit; Zeit > 1; Zeit--)
{
}

should be something like that

for (int counter = Zeit; counter > 1; counter--)
{
    cout << counter;
}

best regards,
p7
Free open source UML modeling tool: ArgoUML

Marcel

Thanks.
-------------- Build: Debug in Timer ---------------

mingw32-g++.exe -Wall -fexceptions  -g     -c C:\C++\Timer\main.cpp -o obj\Debug\main.o
mingw32-g++.exe  -o bin\Debug\Timer.exe obj\Debug\main.o   
obj\Debug\main.o: In function `main':
C:/C++/Timer/main.cpp:32: undefined reference to `PlaySoundA@12'
C:/C++/Timer/main.cpp:56: undefined reference to `PlaySoundA@12'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
2 errors, 0 warnings


Do you know what's wrong here?

I removed the L and I changend the fors to
for (int i = Zeit; i > 1; i--)

Is it standard to initialize the variables in the loops?

JGM

Quote from: Marcel on January 25, 2008, 09:06:40 PM
Is it standard to initialize the variables in the loops?

On C++ is possible, but not on ANSI C

polygon7

Quote from: Marcel on January 25, 2008, 09:06:40 PM
Thanks.
-------------- Build: Debug in Timer ---------------

mingw32-g++.exe -Wall -fexceptions  -g     -c C:\C++\Timer\main.cpp -o obj\Debug\main.o
mingw32-g++.exe  -o bin\Debug\Timer.exe obj\Debug\main.o   
obj\Debug\main.o: In function `main':
C:/C++/Timer/main.cpp:32: undefined reference to `PlaySoundA@12'
C:/C++/Timer/main.cpp:56: undefined reference to `PlaySoundA@12'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
2 errors, 0 warnings


Do you know what's wrong here?
You should add a lib to linker options (but I don't remember which has PlaySound, probably winmm or user32).
best regards,
p7
Free open source UML modeling tool: ArgoUML

Marcel

winmm.lib. But why is in Code::Blocks the winmm.lib now libwinmm.a? MS VC++ 2005 EE was easier... x)

Jenna

Quote from: Marcel on January 25, 2008, 09:06:40 PM
Is it standard to initialize the variables in the loops?

Not necessarily.

If you want to use the last value of the loop-variable outside the loop (like in your "case (1):",  you need to declare the variable outside the loop.
A variable declared in the for-loop's head is only visible inside this loop.

Some very old or broken compilers might ignore that (there might even be a compiler-switch to do so), but it's not standard conform and not reliable.

darthdespotism

Quote from: Marcel on January 25, 2008, 09:32:09 PM
winmm.lib. But why is in Code::Blocks the winmm.lib now libwinmm.a? MS VC++ 2005 EE was easier... x)

You can use MS Toolkit compiler instead of MinGW. I guess there was some #pragma coment() used for Linking which is only supported by VS VC.

In Fact it will be libwinmm.a for MinGW, linked by -lwinmm (gcc adds the lib and .a automatically ;) )

Marcel

Okay thanks at all :)
Yes in VC++ it was #pragma comment (lib, "winmm.lib") ;)