Function in separate Class file isn't working


#1

Hello. I’m trying to learn L-systems and tried to make an algae class that provides N amounts of generations. However when I’m trying to test the function OF refuses to build saying:

Undefined symbols for architecture x86_64:
“algaeClass::generateAlgae(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, int)”, referenced from:
ofApp::setup() in ofApp.o
ld: symbol(s) not found for architecture x86_64

Here’s my code this far, it has been ages since I last used OF so pretty much forgot everything already, so bare with me:

algae hpp file

//  algae.hpp
//  omaLsystem1
#ifndef lsystem_hpp
#define lsystem_hpp

#include <stdio.h>
#include <string>
#include "ofMain.h"

class algaeClass {
public:
    

    string generateAlgae(string word, int iterations);
};

#endif /* algae_hpp */

algae cpp file

//  algae.cpp
//  omaLsystem1

#include "algae.hpp"

string generateAlgae(string word, int iterations) {
    if (iterations == 0) {
        return word;
    }
    
    string newWord = "";
    for (int i = 0; i < word.size(); i++) {
        
        if (word[i] == 'A') {
            newWord += "AB";
        }
        if (word[i] == 'B') {
            newWord += "A";
        }
    }
    string toReturn = "";
    toReturn += generateAlgae(newWord, iterations-1);
    
    return toReturn;
}

ofApp.h

#pragma once

#include "ofMain.h"
#include <string>
#include "algae.hpp"
#include <iostream>

class ofApp : public ofBaseApp{

	public:
		void setup();
		void update();
		void draw();

		void keyPressed(int key);
		void keyReleased(int key);
		void mouseMoved(int x, int y );
		void mouseDragged(int x, int y, int button);
		void mousePressed(int x, int y, int button);
		void mouseReleased(int x, int y, int button);
		void mouseEntered(int x, int y);
		void mouseExited(int x, int y);
		void windowResized(int w, int h);
		void dragEvent(ofDragInfo dragInfo);
		void gotMessage(ofMessage msg);

    algaeClass algae;		
};

Then the function is called with algae.generateAlgae(“A”, 6); etc.

Thanks!


#2

Somehowe your code became unreadable. Could you edit your post and add these lines before and after?

```cpp

…code here…

```


#3

Oh right, it got really messy with the formatting, sorry about that. Now it should be a bit clearer. The function is probably incorrect, I couldn’t test it yet because of the stated error. Hope it makes more sense now.


#4

It looks like you’re missing

algaeClass::

in

string algaeClass::generateAlgae(string word, int iterations)

in the cpp file.


#5

Oh yeah that was it! Thank you very much! I assume that you need to use that :: notation always because of the namespace?