Skip to main content
GameDev.net gamedev.net
🔒 Locked

C++ Primer - CodeBlocks

Started by shadowstep00 Feb 14, 2014 at 8:43 AM 4 replies 3.1k views
Original Post
shadowstep00
shadowstep00

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...
molehill mountaineer
molehill mountaineer
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
shadowstep00
shadowstep00

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

Failure is not an option...
cdoubleplusgood
cdoubleplusgood

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.

shadowstep00
shadowstep00

Thanks. Now it's far more convenient.

Failure is not an option...
NightCreature83
NightCreature83

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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.