C++ Primer - CodeBlocks

Started by
4 comments, last by NightCreature83 10 years, 2 months ago

I was just going to finish the first chapter of C++ Primer(nothing difficult :P ). When I came across


#include <iostream>
#include "Sales_item.h"
int main()
{
  Sales_item book;
  // read ISBN, number of copies sold, and sales price
  std::cin >> book;
  // write ISBN, number of copies sold, total revenue, and average price
  std::cout << book << std::endl;
  return 0;
}

I went to the site the book suggested. Downloaded the MS Visual Studio 2012 files. Then I tried to link the libraries to my project in CodeBlocks and my compiler did not recognise the library "Sales_item.h". Could you help me solve this problem?

Failure is not an option...

Advertisement
Sales_item.h is a header file which you'll find in folder "1" of the .zip you linked to. Most likely the problem is because code::blocks starts looking for this file from a different "starting point" (= working directory) than visual studio.

I'm not familiar with this IDE but I think you could try copying the header file to the directory where the *.cbp (= project file) is located.

EDIT: also take a look at this

Thanks man!! The link you posted solved my problem. :)

Failure is not an option...

By default, Code::Blocks creates a subfolder for new projects, with the name of the project. Check where the project file is located (*.cbp). The *.cpp and *.h should be in the same folder; otherwise you have to add the include folders in the project settings, as explained in the link provided by molehill mountaineer. Do not follow the "workaround" shown there, this is bad practice.

Thanks. Now it's far more convenient.

Failure is not an option...

The next time you get something like this look at the makefile that is specified with the code or the project files, they will tell you how this is compiling. In this case it just compiles all files in the directories as separate exes.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

This topic is closed to new replies.

Advertisement