I am using Xcode on a mac osx with c++ and std project, I get the following error when I try to compile

Build OpenCLCpp of project OpenCLCpp with configuration Debug

Ld build/Debug/OpenCLCpp normal x86_64
cd /Users/mohammadjeragh/Documents/MyResearch/OpenCLCpp
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/g++-4.2 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users/mohammadjeragh/Documents/MyResearch/OpenCLCpp/build/Debug -F/Users/mohammadjeragh/Documents/MyResearch/OpenCLCpp/build/Debug -filelist /Users/mohammadjeragh/Documents/MyResearch/OpenCLCpp/build/OpenCLCpp.build/Debug/OpenCLCpp.build/Objects-normal/x86_64/OpenCLCpp.LinkFileList -mmacosx-version-min=10.6 -framework OpenCL -o /Users/mohammadjeragh/Documents/MyResearch/OpenCLCpp/build/Debug/OpenCLCpp

Undefined symbols:
"sum(int, int)", referenced from:
_main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

here are my 4 files

/*
 *  function.h
 *  OpenCLCpp
 *
 *  Created by Mohammad Jeragh on 7/18/10.
 *  Copyright 2010 KU. All rights reserved.
 *
 */

int sum(int,int);
/*
 *  function.c
 *  OpenCLCpp
 *
 *  Created by Mohammad Jeragh on 7/18/10.
 *  Copyright 2010 KU. All rights reserved.
 *
 */

#include "function.h"

int sum(int a, int b){
	return a + b;
}
#include <iostream>
#include "function.h"

int main (int argc, char **argv) {
    // insert code here...
    std::cout << "Hello, World!\n";
	sum(3, 4);
    return 0;
}

Please Help

You need to link to function.o object file to your code. if you are using g++ you use the -c option to create the .o file and then link the .o's together to create the executable.

Agni, Thank you for your reply.
How can I do that in Xcode?

Actually I found the solution with my problem by adding this to the main.cpp

extern "C"  {
	#include "function.h"

}

Solved the solution.

Thanx guys.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.