tags:

views:

182

answers:

6

Hi .. i am a beginner and i have a problem :

this code doesnt compile :

main.cpp:

#include <stdlib.h>
#include "readdir.h"
#include "mysql.h"
#include "readimage.h"


int main(int argc, char** argv) {
    if (argc>1){
    readdir(argv[1]);
  //  test();
    return (EXIT_SUCCESS);
    }
    std::cout << "Bitte Pfad angeben !" << std::endl ;
    return (EXIT_FAILURE);
}

readimage.cpp

#include <Magick++.h>
#include <iostream>
#include <vector>

using namespace Magick; using namespace std;

void readImage(std::vector<string> &filenames) {
    for (unsigned int i = 0; i < filenames.size(); ++i) {
        try {
            Image img("binary/" + filenames.at(i));

            for (unsigned int y = 1; y < img.rows(); y++) {
                for (unsigned int x = 1; x < img.columns(); x++) {
                    ColorRGB rgb(img.pixelColor(x, y));
                    // cout << "x: " << x << "   y: " << y << " : "  << rgb.red() << endl;
                }
            }
            cout << "done " << i << endl;
        } catch (Magick::Exception & error) {
            cerr << "Caught Magick++ exception: " << error.what() << endl;
        }
    } }

readimage.h

#ifndef _READIMAGE_H
#define _READIMAGE_H

#include <Magick++.h>
#include <iostream>
#include <vector>
#include <string>

using namespace Magick;
using namespace std;

void readImage(vector<string> &filenames)


#endif  /* _READIMAGE_H */

If want to compile it with this code :

g++ main.cpp Magick++-config --cflags --cppflags --ldflags --libs readimage.cpp

i get this error message :

main.cpp:5: error: expected initializer before ‘int’

i have no clue , why ? :(

Can somebody help me ? :)

+7  A: 

In readimage.h, you are missing a semicolon after your readImage function declaration.

awww man... how come , the error is in the main ?! :D
mr.bio
@mr.bio: In fact, the error is just after an #include; this suggests that the error is at the end of the file you are including. And I confess this has happened to me quite a few times.
Gorpik
Because *readimage.h* is the last file to be included into *main.cpp*. `#include ...` is a straight text substitution. An error in an `#include` -ed file affects the compilation of the file that `#include` -ed it...
Mark B
Tnaks.. now i got the point :)
mr.bio
+3  A: 

In readImage.h, you're missing a semicolon after the readImage function prototype.

James Sutherland
+3  A: 

This function declaration:

void readImage(vector<string> &filenames)

is missing a semicolon at the end. An unrelated issue - your include guard names:

#ifndef _READIMAGE_H

are illegal. Names that begin with an underscore and an uppercase letter are reserved in C++ - you are not allowed to create such names yourself.

And in your loop:

for (unsigned int y = 1; y < img.rows(); y++) {

are you sure you should be beginning the loop at 1 and not at zero?

anon
the includeguards are autogenerated by Netbeans
mr.bio
@mr.bio Really? Then netbeans is broken. But I suspect that it is just some textual template that needs fixing,
anon
Thanks .. for the Loop advice .. fixed ;)
mr.bio
+1  A: 

; is missing at the end of readimage.h

Since, main.cpp is pre-processed first, it finds the error at the last line of readimage.h and shows that error occurred before int in main.cpp

main.cpp:5: error: expected initializer before ‘int’

N 1.1
+5  A: 

One of the first things you should do when compiling for the first time is to try one piece of code at a time. Don't throw a bunch of code together and hope that it compiles. Instead, take it one fragment at a time. So here, you might comment out your includes and the code that you expect to use the stuff in those files.

At first glance, it looks like

void readImage(vector<string> &filenames)

is missing a semicolon at the end of the line, since you're declaring it.

Seth Johnson
+1  A: 

You just need a semicolon at the end of readImage declaration in readimage.h:

void readImage(vector<string> &filenames);
Gorpik