Problem - "was no declared in this scope"

0

Witam, mam problem z kompilacją prostego kodu w C++ Allegro ponieważ prawie do każdej linijki kodu pojawia się błąd
was no declared in this scope
Kod programu:

#include <allegro.h>
int main()
{
    allegro_init();
    install_keyboard();
    set_color_depth( 16 );
    set_gfx_mode( GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0 );
    clear_to_color( screen, makecol( 128, 128, 128 ) );
    // RYSOWANIE
    // Piksel
    putpixel( screen, 10, 20, makecol( 255, 0, 255 ) );
    putpixel( screen, 10, 30, makecol( 255, 255, 0 ) );
    // Kąt
    arc( screen, SCREEN_W / 2, SCREEN_H / 2, itofix( 0 ), itofix( 128 ), 100, makecol( 0, 0, 0 ) );
    // Linie
    hline( screen, 20, 400, 500, makecol( 255, 255, 255 ) );
    vline( screen, 20, 400, 500, makecol( 255, 255, 255 ) );
    line( screen, 400, 200, 600, 400, makecol( 255, 128, 64 ) );
    // Trójkąt
    triangle( screen, 20, 20, 60, 60, 20, 60, makecol( 255, 0, 128 ) );
    // Prostokąt
    rectfill( screen, 500, 400, 700, 500, makecol( 128, 30, 30 ) );
    rect( screen, 490, 390, 710, 510, makecol( 30, 30, 30 ) );
    // Okrąg
    circle( screen, 100, 100, 50, makecol( 255, 64, 64 ) );
    circlefill( screen, 100, 100, 40, makecol( 255, 64, 64 ) );
    // Elipsa
    ellipse( screen, 300, 50, 60, 40, makecol( 128, 20, 128 ) );
    ellipsefill( screen, 300, 50, 50, 30, makecol( 128, 20, 20 ) );
    // Wypełnianie
    ellipse( screen, 700, 200, 80, 30, makecol( 50, 50, 50 ) );
    floodfill( screen, 700, 200, makecol( 20, 120, 20 ) );
  
    readkey();
    allegro_exit();
    return 0;
}
END_OF_MAIN(); 

Kod pochodzi ze strony: http://cpp0x.pl/kursy/Kurs-Allegro-4-x-C++/Prymitywy/65

0

Czy przypadkiem nie mówi ci na pierwszą linijkę (#include <allegro.h>) - nie ma takiego pliku?

0

Mówiło tak, ale wkleiłem allegro.h bezpośrednio do CodeBlocks/MinGW/include i już więcej nie było takiego błędu.

||=== Allegrocpp, Debug ===|
G:\Allegrocpp\main.cpp||In function 'int main()':|
G:\Allegrocpp\main.cpp|4|error: 'allegro_init' was not declared in this scope|
G:\Allegrocpp\main.cpp|5|error: 'install_keyboard' was not declared in this scope|
G:\Allegrocpp\main.cpp|6|error: 'set_color_depth' was not declared in this scope|
G:\Allegrocpp\main.cpp|7|error: 'GFX_AUTODETECT_WINDOWED' was not declared in this scope|
G:\Allegrocpp\main.cpp|7|error: 'set_gfx_mode' was not declared in this scope|
G:\Allegrocpp\main.cpp|8|error: 'screen' was not declared in this scope|
G:\Allegrocpp\main.cpp|8|error: 'makecol' was not declared in this scope|
G:\Allegrocpp\main.cpp|8|error: 'clear_to_color' was not declared in this scope|
G:\Allegrocpp\main.cpp|11|error: 'putpixel' was not declared in this scope|
G:\Allegrocpp\main.cpp|14|error: 'SCREEN_W' was not declared in this scope|
G:\Allegrocpp\main.cpp|14|error: 'SCREEN_H' was not declared in this scope|
G:\Allegrocpp\main.cpp|14|error: 'itofix' was not declared in this scope|
G:\Allegrocpp\main.cpp|14|error: 'arc' was not declared in this scope|
G:\Allegrocpp\main.cpp|16|error: 'hline' was not declared in this scope|
G:\Allegrocpp\main.cpp|17|error: 'vline' was not declared in this scope|
G:\Allegrocpp\main.cpp|18|error: 'line' was not declared in this scope|
G:\Allegrocpp\main.cpp|20|error: 'triangle' was not declared in this scope|
G:\Allegrocpp\main.cpp|22|error: 'rectfill' was not declared in this scope|
G:\Allegrocpp\main.cpp|23|error: 'rect' was not declared in this scope|
G:\Allegrocpp\main.cpp|25|error: 'circle' was not declared in this scope|
G:\Allegrocpp\main.cpp|26|error: 'circlefill' was not declared in this scope|
G:\Allegrocpp\main.cpp|28|error: 'ellipse' was not declared in this scope|
G:\Allegrocpp\main.cpp|29|error: 'ellipsefill' was not declared in this scope|
G:\Allegrocpp\main.cpp|32|error: 'floodfill' was not declared in this scope|
G:\Allegrocpp\main.cpp|34|error: 'readkey' was not declared in this scope|
G:\Allegrocpp\main.cpp|35|error: 'allegro_exit' was not declared in this scope|
G:\Allegrocpp\main.cpp|38|error: expected constructor, destructor, or type conversion before ';' token|
||=== Build finished: 27 errors, 0 warnings (0 minutes, 0 seconds) ===|
 
0

A dodałeś stosowne opcje do linkera? O ile pamiętam to akurat allegro tego wymaga

0

Nie, a jak to zrobić?

0

Zrobiłem wszystko tak jak na tej stronie i przy kompilacji kodu podanego na niej pojawia się tylko:

G:\qwwqwqqwqwqwqw\main.cpp||In function 'int main()':|
G:\qwwqwqqwqwqwqw\main.cpp|30|error: 'al_install_timer' was not declared in this scope|
G:\qwwqwqqwqwqwqw\main.cpp|7|warning: unused variable 'bitmap' [-Wunused-variable]|
||=== Build finished: 1 errors, 1 warnings (0 minutes, 0 seconds) ===|
 

A przy kompilacji poprzedniego kodu jest bez zmian

3

Zamiast kopiować pojedyńcze nagłówki lepiej dodaj ścieżkę z nagłówkami do allegro do projektu. Skopiowanie pojedyńczego pliku nie oznacza że już jest ok. Skopiowany nagłówek może załączać inne nagłówki i dlatego masz taki błąd.

0
Hostel napisał(a):

Zamiast kopiować pojedyńcze nagłówki lepiej dodaj ścieżkę z nagłówkami do allegro do projektu. Skopiowanie pojedyńczego pliku nie oznacza że już jest ok. Skopiowany nagłówek może załączać inne nagłówki i dlatego masz taki błąd.

Zrobiłem tak jak napisałeś i to co jest na tej stronie http://wiki.allegro.cc/index.php?title=Build/Using_allegro5.org_precompiled_binaries/MinGW, I dało mi to tylko tyle że nie musze przenosić allegro.h bezpośrednio do include żeby nie pojawiało się "no such file or directory".

0

Na sucho przyjrzałem się plikowi projektu oraz popatrzyłem pod linuksem jak się ten plik zmienia gdy np. dodaje się ścieżkę do nagłówkó i wygląda to tak, że chyba źle dodałeś ścieżkę, ale głowy sobie nie dam uciąć. Upewnij się w takim razie czy nagłówki do allegro dodałeś w poprawny sposób a brzmi on prawdopodobnie tak:

Prawy przycisk myszy na projekcie -> Build options... -> Search directiories -> Compiler - tutaj dodajesz ścieżdkę do folderu include z allegro.

0

Zrobiłem tak jak kazałeś ale nic to nie dało.

0

U mnie dzieje się identycznie, przy czym zajrzałem do timer.h
i tam jest AL_FUNC(ALLEGRO_TIMER*, al_create_timer, (double speed_secs));

więc może sprawdź czy zaskoczy Ci z al_create_timer zamiast install...
niestety u mnie wywala błąd linkera... że nie możne znaleźć -lallegro
choć wszystkie biblioteki wrzuciłem do mingw/lib

szczerze powiem, że to pierwszy raz kiedy dodawałem coś do linkera, więc
nie bardzo wiem jeszcze na czym to polega.

0

Okay, przepraszam za chaos a także za dodatkowy post, nie mam tu konta zatem nie mogę edytować.
Założę na dniach ^^ a moda proszę o sklejenie. I jeszcze raz przepraszam.

A teraz tak:

Ogólnie rzecz biorąc mam czysty system.
MinGW 4.7.2
Code::Blocks 12.11
bez żadnych dodatków, udziwnień.. nic.
Ściągnąłem sobie allegro5 i zrobiłem sobie ten
test tak jak w tutku jest podane, z tą różnicą,
że pliki nagłówkowe wrzuciłem do mingw/include/allegro5
a biblioteki do mingw/lib

Tak samo mi wywalało błąd al_install_timer
po zmianie na al_create_timer już tylko

not found -lallegro
not found -lallegro_main

zapewne zbyt dosłownie -przepisałem- owe parametry.
teraz zmieniłem na:

 
C:\MinGW\lib\liballegro-5.0.8-mt.a

I działa. Nie wiem jeszcze czym się różni *mt.a od *md.a
ale to już trzeba jutro przeczytać. Mam nadzieję że i u Ciebie
zadziała.

"Zbożnej nocy życzę" :)

0
dazuji napisał(a):

I działa. Nie wiem jeszcze czym się różni *mt.a od *md.a
ale to już trzeba jutro przeczytać. Mam nadzieję że i u Ciebie
zadziała.

Google podpowiada takie zapytanie: allegro md or md
Pierwszy link i jest odpowiedź:
https://www.allegro.cc/manual/5/install/windows.html

MT vs MD

These options affect how the compiler links to the standard C library. The MT version includes it as part of the executable. The MD version leaves it out, and requires you to also include the appropriate system DLLs when you distribute your program.

1 użytkowników online, w tym zalogowanych: 0, gości: 1