Doubt compiling cpp and .h file

1

Good morning everyone, you see, I have the following files:

  • main.cpp where that class and functions are used.
  • Time.cpp: with definitions of class functions
  • Time.h: with class, member functions + data member.

I would like to compile them all, I have read a lot of creating objects from those files, but still I can not compile them. Could someone explain to me how to compile them all? As I read Here and Here I would need to create the main object, create time object file and then link main with Time, then I tried this line for example:

g++ -c Tiempo.cpp -o Tiempo

But it does not work for me, can someone help me?

Thank you very much in advance.

EDIT: Extensive data: I've also tried with: gcc -c Time.cpp or gcc -c main.cpp but it shows me the same error, whatever I do (generate object code or anything else).

./Tiempo.h:1:1: error: source file is not valid UTF-8
<CF><FA><ED><FE><U+0007><U+0000><U+0000><U+0001><U+0003><U+0000><U+0000>...

./Tiempo.h:1:2: error: source file is not valid UTF-8
<CF><FA><ED><FE><U+0007><U+0000><U+0000><U+0001><U+0003><U+0000><U+0000>...

and so on ...

    
asked by ProgrammerJr 08.01.2018 в 11:20
source

1 answer

1

When you compile a program that has several files, you can do it in several ways. For this case, perhaps the simplest option is to directly compile all the cpps together in the final executable:

g++ Tiempo.cpp main.cpp -o Tiempo

The problem that you seem to have has nothing to do with the commands themselves, but with the encoding of the .h file. I would suggest you look at what kind of file it is. In linux you can do it through the file command.

file Tiempo.h

Maybe this gives you some clue.

    
answered by 12.01.2018 / 00:18
source