c++ - Compiling header and cpp files in g++ -


i have problem compile multiple files using gnu g++, please me.

we assume there 5 files:

main.cpp : main function  a.h      : header file of class  a.cpp    : definition of class  b.h      : header file of class b  b.cpp    : definition of class b 

in program, main.cpp uses class (thus including a.h) , class uses class b (thus including b.h).

so, how compile program generate executive file?

i tried use following command, feedbacked error:

undefined reference ~(objects in class , b)".  command: g++ -wall -o2 -s main.cpp 

and operating system ubuntu 12.04. know if make project stuff dev c++ automaticly link files don't want use that. i've seen other links , sources couldn't find useful myself.

try

g++ -wall -o2 main.cpp a.cpp b.cpp 

this create program a.out executable. -wall flag tells compiler issue more warnings, , -o2 flag enables optimizations. last 3 arguments source files. need give source files not #include:d in way g++.

you can specify executable name option -o (name).


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -