SocrateZ Temat założony przez niniejszego użytkownika |
VS2008 - error LNK2019 » 2012-08-14 22:45:24 No właśnie, jak w tytule... Problem z tym błędem mam :/ Plik pierwszy ( header ) #ifndef _al_minor_creek #define _al_minor_creek
#include <stdlib.h>
struct MINOR_CREEK { unsigned short startX; unsigned short startY; unsigned short stopX; unsigned short stopY; };
struct MINOR_CREEK * creek_create( unsigned short x, unsigned short y, unsigned short width, unsigned short height );
#endif
Plik drugi: #include "creek.h"
struct MINOR_CREEK * creek_create( unsigned short x, unsigned short y, unsigned short width, unsigned short height ) { struct MINOR_CREEK * creek; creek =( struct MINOR_CREEK * ) malloc( sizeof( struct MINOR_CREEK ) ); creek->startX = x; creek->startY = y; creek->stopX = width + x; creek->stopY = height + y; return creek; }
main: int main( void ) { ... MINOR_CREEK * minor = al_creek_create( 50, 50, 200, 50 ); ... }
No i ten kod skutkuje błędem: main.obj : error LNK2019: unresolved external symbol "struct MINOR_CREEK * __cdecl creek_create(unsigned short,unsigned short,unsigned short,unsigned short)" (?creek_create@@YAPAUMINOR_CREEK@@GGGG@Z) referenced in function _main
I nie pojmuje :/ Proszę o pomoc... --------------------------------------------------------- PS: Aha, pracuje w Visual Studio 2008, jak w tytule :D |
|
DejaVu |
» 2012-08-14 23:18:00 1. Dołącz do projektu pliki *.c 2. Czemu piszesz w C? 3. Wywołujesz inną funkcję niż ta, którą napisałeś. |
|
SocrateZ Temat założony przez niniejszego użytkownika |
» 2012-08-14 23:23:36 Wiem, przepraszam, mój błąd... Źle przepisałem...
Piszę w C, wiem że mógłbym użyć free i delete z C++ ale tutaj akurat muszę pisać w C Niestety :/
To przez bibliotekę Allegro... piszę do niej GUI, a napisana jest w C
PS: Yyyyy... punkt 1 i 2 się pokrywają :) PS2: Błąd nadal występuje ( żeby nie było... ) |
|
SocrateZ Temat założony przez niniejszego użytkownika |
» 2012-08-15 12:15:07 Co dziwne, jak zrobię tak:
#include <allegro5/allegro.h> #include <allegro5/allegro_primitives.h> #include <allegro5/allegro_font.h> #include <allegro5/allegro_ttf.h> #include <iostream>
struct GUI_INPUT { unsigned short startx; unsigned short starty; unsigned short stopx; unsigned short stopy; };
struct GUI_INPUT * al_gui_input_create( unsigned short x, unsigned short y, unsigned short width, unsigned short height ) { GUI_INPUT * input =( struct GUI_INPUT * ) malloc( sizeof( struct GUI_INPUT ) ); input->startx = x; input->starty = y; input->stopx = width + x; input->stopy = height + y; return input; }
int main( void ) { al_init(); al_init_font_addon(); al_init_ttf_addon(); al_install_keyboard(); ALLEGRO_DISPLAY * display = al_create_display( 800, 600 ); ALLEGRO_EVENT_QUEUE * queue = al_create_event_queue(); ALLEGRO_TIMER * timer = al_create_timer( 1.0 / 60 ); ALLEGRO_FONT * font = al_load_font( "DejaVuSans.ttf", 16, 0 ); al_gui_input_create( 20, 20, 100, 20 ); ALLEGRO_USTR * string = al_ustr_new( "" ); bool run = true; bool redraw = true; al_register_event_source( queue, al_get_keyboard_event_source() ); al_register_event_source( queue, al_get_timer_event_source( timer ) ); al_start_timer( timer ); while( run ) { ALLEGRO_EVENT event; al_wait_for_event( queue, & event ); if( event.type == ALLEGRO_EVENT_TIMER ) { redraw = true; } else if( event.type == ALLEGRO_EVENT_KEY_UP ) { if( event.keyboard.keycode == ALLEGRO_KEY_ESCAPE ) run = false; } else if( event.type == ALLEGRO_EVENT_KEY_CHAR ) { if( event.keyboard.unichar != 0 ) al_ustr_append_chr( string, event.keyboard.unichar ); } if( redraw && al_is_event_queue_empty( queue ) ) { al_draw_ustr( font, al_map_rgb( 255, 255, 255 ), 50, 50, 0, string ); al_flip_display(); al_clear_to_color( al_map_rgb( 0, 0, 0 ) ); } } }
Działa...
Jak rozłoże na dwa pliki ( h i c ) nie działa
Co jest grane?
To wygląda, jakby kompilator nie widział tej struktury, gdy usunę znacznik wskaźnika ( * ) to pisze że struktura GUI_INPUT nie istnieje:
Input.c:
#include "input.h"
struct GUI_INPUT al_gui_input_create( unsigned short x, unsigned short y, unsigned short width, unsigned short height ) { GUI_INPUT input =( GUI_INPUT ) malloc( sizeof( GUI_INPUT ) ); input.startx = x; input.starty = y; input.stopx = width + x; input.stopy = height + y; return input; }
Input.h
#ifndef _al_gui_input #define _al_gui_input
#include <allegro5/allegro.h>
typedef struct { unsigned short startx; unsigned short starty; unsigned short stopx; unsigned short stopy; } GUI_INPUT;
struct GUI_INPUT al_gui_input_create( unsigned short x, unsigned short y, unsigned short width, unsigned short height );
#endif
Main.c
#include <allegro5/allegro.h> #include <allegro5/allegro_primitives.h> #include <allegro5/allegro_font.h> #include <allegro5/allegro_ttf.h> #include <iostream>
#include "input.h"
int main( void ) { al_init(); al_init_font_addon(); al_init_ttf_addon(); al_install_keyboard(); ALLEGRO_DISPLAY * display = al_create_display( 800, 600 ); ALLEGRO_EVENT_QUEUE * queue = al_create_event_queue(); ALLEGRO_TIMER * timer = al_create_timer( 1.0 / 60 ); ALLEGRO_FONT * font = al_load_font( "DejaVuSans.ttf", 16, 0 ); GUI_INPUT input = al_gui_input_create( 20, 20, 100, 20 ); ALLEGRO_USTR * string = al_ustr_new( "" ); bool run = true; bool redraw = true; al_register_event_source( queue, al_get_keyboard_event_source() ); al_register_event_source( queue, al_get_timer_event_source( timer ) ); al_start_timer( timer ); while( run ) { ALLEGRO_EVENT event; al_wait_for_event( queue, & event ); if( event.type == ALLEGRO_EVENT_TIMER ) { redraw = true; } else if( event.type == ALLEGRO_EVENT_KEY_UP ) { if( event.keyboard.keycode == ALLEGRO_KEY_ESCAPE ) run = false; } else if( event.type == ALLEGRO_EVENT_KEY_CHAR ) { if( event.keyboard.unichar != 0 ) al_ustr_append_chr( string, event.keyboard.unichar ); } if( redraw && al_is_event_queue_empty( queue ) ) { al_draw_ustr( font, al_map_rgb( 255, 255, 255 ), 50, 50, 0, string ); al_flip_display(); al_clear_to_color( al_map_rgb( 0, 0, 0 ) ); } } }
Nadal ten sam błąd:
error LNK2019: unresolved external symbol "struct GUI_INPUT __cdecl al_gui_input_create(unsigned short,unsigned short,unsigned short,unsigned short)" (?al_gui_input_create@@YA?AUGUI_INPUT@@GGGG@Z) referenced in function _main
Ten głupi: LNK2019 |
|
SocrateZ Temat założony przez niniejszego użytkownika |
» 2012-08-15 14:34:02 Problem rozwiązany
Nie wiem dlaczego, ale w pliku input.h muszę dodać na końcu linijkę:
#include "input.c"
#ifndef _al_gui_input #define _al_gui_input
#include <allegro5/allegro.h>
struct GUI_INPUT { unsigned short startx; unsigned short starty; unsigned short stopx; unsigned short stopy; };
struct GUI_INPUT * al_gui_input_create( unsigned short x, unsigned short y, unsigned short width, unsigned short height );
#include "input.c"
#endif
|
|
Mrovqa |
» 2012-08-15 15:15:30 Obstawiam, iż plik "input.c" nie został dodany do projektu ;) Z tegoż to powodu musiałeś go doinkludowywać. Spróbuj go wywalić z projektu i dodać jeszcze raz. |
|
« 1 » |