dev c++ 사용하는데 링크가 안되요.
글쓴이: quintus / 작성시간: 일, 2004/05/02 - 2:57오전
dev c++ 첨 써보는데 hello world 까지는 잘 컴파일되고 실행 되는데
파일을 여러개로 나눠서 build all 하니까 자꾸 에러가 나네요. 왜그런거죠.
뭔가 설정해줘야 하는게 있나요?
Quote:
C:\DEV-C_~1\Lib\\libmingw32.a(main.o)(.text+0x8e): undefined reference to `WinMain@16'
file -> new project -> console application -> ok 해서 project 열고
addtoproject 해서 필요한 파일을 넣고
buildall 을 했는데 컴파일 까지는 되는데 링크가 안 되는거 같아요
밑에 파일 4개 컴파일 하려고 합니다.
// readvar.cpp // write a stream of persons, using fstream.h #include <fstream.h> #include <strstream.h> #include <string.h> #include "writeper.cpp" istream & operator >> (istream & stream, Person& p) { // read fields from stream char delim; stream.getline(p.LastName, 30,'|'); if (strlen(p.LastName)==0) return stream; stream.getline(p.FirstName,30,'|'); stream.getline(p.Address,30,'|'); stream.getline(p.City, 30,'|'); stream.getline(p.State,15,'|'); stream.getline(p.ZipCode,10,'|'); return stream; } int ReadVariablePerson (istream & stream, Person & p) { // read a variable sized record from stream and store it in p // if read fails, set p.LastName to empty string and return 0 short length; stream . read ((char *)&length, sizeof(length)); if (stream . fail()){p.LastName[0]=0; return 0;} char * buffer = new char[length+1]; stream . read (buffer, length); buffer [length] = 0; // terminate buffer with null istrstream strbuff (buffer); strbuff >> p; return 1; } int main(){ char filename [20]; Person p; cout << "Enter the file name:"<<flush; cin.getline(filename, 19); ifstream stream (filename, ios::in); if (stream.fail()) { cout << "File open failed!" <<endl; return 0; } while (1) { // read fields of person ReadVariablePerson (stream, p); if (strlen(p.LastName)==0) break; // write person to file cout << p; } }
// person.h #ifndef PERSON #define PERSON class Person { public: // data members char LastName [11]; char FirstName [11]; char Address [16]; char City [16]; char State [3]; char ZipCode [10]; // method Person (); // default constructor }; Person::Person () {//constructor LastName[0]=0; FirstName[0]=0; Address[0]=0; City[0]=0; State[0]=0; ZipCode[0]=0; } #endif
// writeper.cpp #include <iostream.h> #include "person.h" ostream & operator << (ostream & stream, Person & p) { // insert fields into file stream<< "Last Name '" << p.LastName <<"'\n" << "First Name '" << p.FirstName <<"'\n" << "Address '" << p.Address <<"'\n" << "City '" << p.City <<"'\n" << "State '" << p.State <<"'\n" << "Zip Code '" << p.ZipCode <<"'\n" <<flush; return stream; }
// person.cpp #include <iostream.h> #include <string.h> #include "person.h" istream & operator >> (istream & stream, Person & p) { // read fields from input cout<<"Enter last name, or <cr> to end: "<<flush; stream.getline (p.LastName, 30); if (strlen(p.LastName)==0) return stream; cout<<"Enter first name: "<<flush; stream.getline(p.FirstName,30); cout<<"Enter address: "<<flush; stream.getline(p.Address,30); cout<<"Enter city: "<<flush; stream.getline(p.City, 30); cout<<"Enter state: "<<flush; stream.getline(p.State,15); cout<<"Enter zip code: "<<flush; stream.getline(p.ZipCode,10); return stream; }[/code]
Forums:
댓글 달기