Import class from directory

Hello I try to import class from a directory, but I receive an error message :

Undefined symbols for architecture x86_64:
  "Mother::Mother()", referenced from:
      ofApp::setup() in ofApp.o
  "Mother::~Mother()", referenced from:
      ofApp::setup() in ofApp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I don’t understand because the code work with this architectory with ‘clang++’ in direct ‘c++’ may be I miss somthing to import my file ? but in the screenshot we see all file is imported. For imformation there is no problem with file directory for the Template or function file, only with classes put in directory, that’s work too when the class file is on the root. I hope it’s clear and any body have a solution for me. Have a good day.

Here a simple code to reproduce :


#ifndef MOTHER_H
# define MOTHER_H

#include <iostream>
#include <string>

class Mother {


#include "Mother.hpp"

Mother::Mother() {

Mother::~Mother() {


#pragma once

#include "ofMain.h"
#include "other/Mother.hpp"

class ofApp : public ofBaseApp{

		void setup();
		void draw();		


#include "ofApp.h"
#include "other/Mother.hpp"

void ofApp::setup(){
	Mother mother;

I forget to write about my configuration : OSX 10.14.8 / Xcode 10.3.1

If u click on Mother.cpp in that menu, then look in the file inspector, (view -> inspectors -> show file inspector) make sure the checkbox for the app in target membership is selected

Hi @StanLepunK check what @dizzy is saying.
If that does not work just update your project with Project Generator and the files will be linked properly.
If you want to create new files, do it through Xcode to avoid this problem, as it will automatically do this, otherwise if you create these files externaly you’ll need to either update with PG or do what @dizzy says.

@dizzy thx for your advice, I test your solution, but I don’t find the check box to target the membership.
For information I imported the file with the contextual menu add file

@roymacdonald I try to update the project, to do that I open the project generator and import my project and click on generate.

Unfortunately for the both solutions the problem stay the same.

I have a same problem with a pure c++ file.

Plus I find a post about that, but these one is very old and I fail to implemented the solution :

I do that a lot and I dont have problems.
It is weird that the target membership is not shown in the file inspector.

Probably the projects file path with spaces is messing up the whole thing.

when you chose Add files to "other" the following panel should open

In the bottom options make sure these are added to the target.

I was able to compile a project based on the code you posted, although I am on xcode 11.2.1. I remember that xcode 10 was quite nasty. Maybe try to update it.
I just copy pasted the code you posted and created a new project with it and it worked immediately.
Just a detail. In ofApp.cpp you are adding again the include for mother.h, which is not necesary as it is already include in ofApp.h.

Last but not least,
Make sure that the mother file is in the compile sources. look at the following screenshot.

1 Like

It’s my first time with Xcode… i don’t knew it’s a nasty soft, but I’m a nasty stan, so I can make with it :slight_smile:
my Xcode is Version 11.3.1 (11C504)
I find a way of the bug if it is a bug. When I import *.hpp and *.cpp in folder other that’s work. The problem is when I try to import the folder other with the files. I look in the file *.xcodeproj

work when the folder is created and the files is imported in folder create with Xcode

/* Begin PBXFileReference section */
		F6BBCEB724A5E24400E24663 /* cpp_test_2 */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = cpp_test_2; sourceTree = BUILT_PRODUCTS_DIR; };
		F6BBCEBA24A5E24400E24663 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
		F6BBCEC224A5E29800E24663 /* Mother.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Mother.cpp; sourceTree = "<group>"; };
		F6BBCEC324A5E29800E24663 /* Mother.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Mother.hpp; sourceTree = "<group>"; };
/* End PBXFileReference section */

don’t work when the folder is imported, the link is not created.

/* Begin PBXBuildFile section */
		F6BBCED224A5E5EE00E24663 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6BBCED124A5E5EE00E24663 /* main.cpp */; };
/* End PBXBuildFile section */

I try to update my xcode to see if the problem stay. Thx for your advices.

@roymacdonald I don’t read well the end of your message about the build phase that’s a solution when the folder is imported with files. It’s necessary to update the file path by this way. Thanks a lot !!!

1 Like

This is super odd. Is the others folder inside the project’s src folder in your hard drive?
If not try putting it there and update with project generator.
The build phase is kind of a last resort but you should be able to do it with out it and just the project generator.

Like you say it’s odd, because that’s work with the template and the function but not with the classes, but I’ve the same probleme with the classic c++ files, not only with ofx. So I think the problem don’t come from ofx, maybe my computer or something else.
That’s true it’s little boring to import manually from build phase but my mini library is small at this time so that’s enough for now :slight_smile: In the future I will try to dig around this problem… but I don’t have a lot time to do… I must return fast to learn react js and typescript before the end of the summer !!! And thks again for answer that’s very cool !

Hi, well it definitely is a problem with your xcode install. Xcode is a bit nasty, as you said, and there are times it works in some horrible ways. Good luck with your learning.