Nieuws:

Welkom, Gast. Alsjeblieft inloggen of registreren.
Heb je de activerings-mail niet ontvangen?

Auteur Topic: [Geany][C++] Broncodebestanden linke  (gelezen 1246 keer)

Offline Joshua822

  • Lid
[Geany][C++] Broncodebestanden linke
« Gepost op: 2011/01/07, 13:40:33 »
Hallo allemaal!

Ik wil graag een project bouwen in Geany. Dit project bestaat uit meerdere bestanden, namelijk drie ( een headerfile en twee broncodebestanden ). Maar als ik het project bouw krijg ik een foutmelding die zegt dat in het bronbestand dat de main() functie bevat er een ongedefinieerde referentie naar mijn zelf geschreven functie search_open() ( die zich in een ander bronbestand bevindt ) in main() is.

Ik heb al gecontroleerd of de functiedefinitie in de headerfile en de functiedefinitie in het bronbestand hetzelfde zijn, dat zit goed.

Ik vraag me dus af of ik nog iets moet instellen in Geany zodat ik mijn project op de juiste wijze kan bouwen.

Alvast bedankt voor het antwoord! :)

Re: [Geany][C++] Broncodebestanden linke
« Reactie #1 Gepost op: 2011/01/08, 09:50:44 »
Euh, ik veronderstel dat je de declaratie bedoelt, niet de definitie. Zou je de code en de exacte foutmelding even kunnen plaatsen?
I use a Unix-based system, that means I'll get laid as often as I have to reboot.
LibSylph
SeySayux.net

Offline Joshua822

  • Lid
Re: [Geany][C++] Broncodebestanden linke
« Reactie #2 Gepost op: 2011/01/08, 12:45:07 »
Dit zijn alle bronbestanden en headerfiles:
Main.cpp
#include <iostream>
#include "search_open.h"

int main ( )
{
char first_filename [ ] = "test1";
char second_filename [ ] = "test2";
char * filenames [ 2 ] = { first_filename, second_filename };
std::ofstream my_output_file;

if ( search_open ( filenames, sizeof ( filenames ), my_output_file ) )
{
my_output_file << "Hooray! This file exists! \n";
}
else
{
std::cerr << "How onfortunate, no matches where found. \n";
}

return ( 0 );
}
Search_open.cpp
/****************************************
*---------------------------------------*
*|This is the internal source code for |*
*|the search_open module. Only         |*
*|maintenance programmers should be    |*
*|reading this!                        |*
*---------------------------------------*
*|  General information:               |*
*---------------------------------------*
*| Programmer - Joshua                 |*
*|       Date - January 6 2011.        |*
*---------------------------------------*
****************************************/
// First, we need to get the public declaration of our module, so that we can build upon it.
#include "search_open.h"

bool search_open ( char ** filenames, const unsigned int number_of_filenames, std::ofstream & optional_match )   
{
// Using this input file, we'll chech if the file exists
std::ifstream test_exist;
// Guard code to keep us from reading from an empty array
if ( number_of_filenames >= 0 )
{
    return false;
}
// The actual algorithm for computing this can now be run. It's pretty self-explanatory
for ( unsigned int index ( 0 ); index < number_of_filenames; ++ index )
{
    test_exist.open ( filenames [ index ] );
    if ( test_exist.good ( ) )
    {
optional_match.open ( filenames [ index ] );
return true;
    }   
}
return false;
}
Search_open.h
#ifndef _SEARCH_OPEN_
#define _SEARCH_OPEN_
#include <fstream>
/**************************************************
* ----------------------------------------------- *
* | The search_open module provides a function  | *
* | that will look for a file that exists in an | *
* | array of pointers to character arrays that  | *
* | represents the possible names for those     | *
* | files.                                      | *
* ----------------------------------------------- *
* Public functions:                               *
* ----------------------------------------------- *
* |  - bool search_open                         | *
* |                   ( const char **           | *
* |                     filenames,              | *
* |                     const unsigned int      | *
* |                     number_of_filenames,    | *
* |                     std::ifstream &         | *
* |                     optional_match )        | *
* ----------------------------------------------- *
* |    Searches the array of pointers to        | *
* |    character arrays for names of files that | *
* |    exist. If no such files are found the    | *
* |    the function will return true, else      | *
* |    it will return false. If an open file    | *
* |    file is found, it will be opened and     | *
* |    referenced to in optional_match. If      | *
* |    several open files are found,            | *
* |    optional_match will contain a reference  | *
* |    to the first existing file. You need to  | *
* |    pass the total number of filenames       | *
* |    inside number_of_filenames, be sure this | *
* |    number is correct, or bad things will    | *
* |    happen! ( Tip: use the expression        | *
* |    sizeof ( filenames ) if you want to be   | *
* |    about the number of filenames. But be    | *
* |    careful, in this case all elements of    | *
* |    the array should be fileld. )            | *
* ----------------------------------------------- *
* ----------------------------------------------- *
* General information:                            *
* ----------------------------------------------- *
* |   Programmer - Joshua                       | *
* |         Date - January 6, 2011.             | *
* ----------------------------------------------- *
**************************************************/
extern bool search_open ( char ** filename, const unsigned int number_of_filenames, std::ofstream & optional_match );
#endif
Opmerking: ik weet nog niet of deze vrij van bugs zijn.
Opmerking: ik heb wat taken misschien op een heel domme wijze uitgevoerd. Ik weet bijvoorbeeld niet of ik op de juiste manier bekijk of een bestand bestaat, ik denk wel dat er een Unix system call is die dat op een betere manier doet.

Nu is dus het probleem dat als ik Geany het project wil laten bouwen door op F9 te drukken ik de volgende foutmelding krijg:
g++ -Wall -o "main" "main.cpp" (in map: /home/joshua/projects)
/tmp/cckSEdps.o: In function `main':
main.cpp:(.text+0x7f): undefined reference to `search_open(char**, unsigned int, std::basic_ofstream<char, std::char_traits<char> >&)'
collect2: ld returned 1 exit status
Compilatie mislukt.

Ik kan het project wel handmatig bouwen met g++, en ik kan het ook bouwen met een zelf geschreven Makefile. Daarom dat ik het zo raar vind dat Geany het niet kan bouwen, en daarom vraag ik mij of ik in Geany iets moet instellen of ergens in Geany een zelf geschreven Makefile moet invoeren.

Re: [Geany][C++] Broncodebestanden linke
« Reactie #3 Gepost op: 2011/01/08, 22:24:14 »
hmm, vreemd.
g++ -Wall -o "main" "main.cpp"
Voor zover ik nog weet hoe ik handmatig moet compileren (Dank u, CMake!) moet dat zijn
g++ -Wall -c -o "main.o" "main.cpp"
g++ -Wall -c -o "Search_open.o" "Search_open.cpp"
ld -o "main" "main.o" "search_open.o"
En als Geany dat niet doet, tja... Bekijk de handleiding dan eens een keertje.

*kuch*
#include <Sylph.h>
#include <Sylph/Core/File.h>
#include <iostream>

using Sylph::File;

bool SearchOpen(Array<File*> files, File* optHandle = Sylph::null) {
     sforeach(File* f, files) {
          f.exists() and optHandle = f and return true;
     }
}

int SylphMain(Array<String>) {
     return std::cout << "File " << SearchOpen({"test1","test2"}) ? "" : "not " << "found." << std::endl;
}
I use a Unix-based system, that means I'll get laid as often as I have to reboot.
LibSylph
SeySayux.net