LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   creating a project with directory strucure. (https://www.linuxquestions.org/questions/programming-9/creating-a-project-with-directory-strucure-188252/)

sheenak 05-31-2004 10:51 PM

creating a project with directory strucure.
 
Hi,

I am using kdeveloper to create a C++ project.
I have created a directory structure in it.
for eg,
test_dir :main folder
Include, Src : sub folders in test_dir
prj1, prj2: sub folders in Include ( to include .h header files)
prj1, prj2: sub folders in Src ( to include .cpp source files)
let b1.h, b2.h, b1.cpp, b2.cpp are the header and source files included in prj1, prj2, prj1, prj2 resp.

let b1.h be
----------------

#ifndef STRREV
#define STRREV
#include<iostream.h>

void strrev(char * source);

#endif

let b2.h be
-----------------

#ifndef STRLEN
#define STRLEN
#include< iostream.h>

int strlen1(char *);

#endif

let b1.cpp be
------------------
#include "/home/sheena/test_dir/test_dir/Include/prj2/b2.h" //path for include file
#include "/home/sheena/test_dir/test_dir/Include/prj1/b1.h"

void strrev(char * source)
{
int i,j;
char dest;
int n=strlen1(source);
for(i=0,j=n-1;i<j;i++,j--)
{
dest = source[i];
source[i]=source[j];
source[j]= dest;
}
source[n]='\0';
cout<<source;
}

int strlen1(char *source)
{
int n=0;
while(source[n] != '\0')
n++;
return n;
}


let b2.cpp be
------------------
#include "/home/sheena/test_dir/test_dir/abc1/a2/b2.h"
#include "/home/sheena/test_dir/test_dir/abc1/a1/b1.h"

int main()
{
int n;
char * source ="sheena";
strrev(source);
n= strlen1(source);
cout<<"\n length is "<<n<<endl;
return 0;
}

------------------------------------------------------------------------------------

All my files b1.cpp and b2.cpp are compiling successfully, but during executing this small program i am getting some linking error like follow:

gmake: Entering directory `/home/sheena/test_dir'
gmake all-recursive
gmake[1]: Entering directory `/home/sheena/test_dir'
Making all in test_dir
gmake[2]: Entering directory `/home/sheena/test_dir/test_dir'
Making all in abc1
gmake[3]: Entering directory `/home/sheena/test_dir/test_dir/abc1'
Making all in a1
gmake[4]: Entering directory `/home/sheena/test_dir/test_dir/abc1/a1'
gmake[4]: Nothing to be done for `all'.
gmake[4]: Leaving directory `/home/sheena/test_dir/test_dir/abc1/a1'
Making all in a2
gmake[4]: Entering directory `/home/sheena/test_dir/test_dir/abc1/a2'
gmake[4]: Nothing to be done for `all'.
gmake[4]: Leaving directory `/home/sheena/test_dir/test_dir/abc1/a2'
gmake[4]: Entering directory `/home/sheena/test_dir/test_dir/abc1'
gmake[4]: Nothing to be done for `all-am'.
gmake[4]: Leaving directory `/home/sheena/test_dir/test_dir/abc1'
gmake[3]: Leaving directory `/home/sheena/test_dir/test_dir/abc1'
Making all in abc2
gmake[3]: Entering directory `/home/sheena/test_dir/test_dir/abc2'
Making all in a1
gmake[4]: Entering directory `/home/sheena/test_dir/test_dir/abc2/a1'
source='b1.cpp' object='b1.o' libtool=no \
depfile='.deps/b1.Po' tmpdepfile='.deps/b1.TPo' \
depmode=gcc3 /bin/sh ../../../admin/depcomp \
g++ -DHAVE_CONFIG_H -I. -I. -I../../.. -Wnon-virtual-dtor -Wno-long-long -Wbad-function-cast -Wundef -Wall -pedantic -W -Wpointer-arith -Wmissing-prototypes -Wwrite-strings -ansi -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -Wcast-align -Wconversion -O2 -O0 -g3 -Wall -fno-exceptions -fno-check-new -c -o b1.o `test -f b1.cpp || echo './'`b1.cpp
In file included from /usr/include/c++/3.2/backward/iostream.h:31,
from /home/sheena/test_dir/test_dir/abc1/a2/b2.h:19,
from b1.cpp:18:
/usr/include/c++/3.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
b1.cpp:44:2: warning: no newline at end of file
rm -f liba1.a
ar cru liba1.a b1.o
ranlib liba1.a
gmake[4]: Leaving directory `/home/sheena/test_dir/test_dir/abc2/a1'
Making all in a2
gmake[4]: Entering directory `/home/sheena/test_dir/test_dir/abc2/a2'
source='b2.cpp' object='b2.o' libtool=no \
depfile='.deps/b2.Po' tmpdepfile='.deps/b2.TPo' \
depmode=gcc3 /bin/sh ../../../admin/depcomp \
g++ -DHAVE_CONFIG_H -I. -I. -I../../.. -Wnon-virtual-dtor -Wno-long-long -Wbad-function-cast -Wundef -Wall -pedantic -W -Wpointer-arith -Wmissing-prototypes -Wwrite-strings -ansi -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -Wcast-align -Wconversion -O2 -O0 -g3 -Wall -fno-exceptions -fno-check-new -c -o b2.o `test -f b2.cpp || echo './'`b2.cpp
In file included from /usr/include/c++/3.2/backward/iostream.h:31,
from /home/sheena/test_dir/test_dir/abc1/a2/b2.h:19,
from b2.cpp:17:
/usr/include/c++/3.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
b2.cpp: In function `int main()':
b2.cpp:24: warning: deprecated conversion from string constant to `char*'
rm -f liba2.a
ar cru liba2.a b2.o
ranlib liba2.a
gmake[4]: Leaving directory `/home/sheena/test_dir/test_dir/abc2/a2'
gmake[4]: Entering directory `/home/sheena/test_dir/test_dir/abc2'
gmake[4]: Nothing to be done for `all-am'.
gmake[4]: Leaving directory `/home/sheena/test_dir/test_dir/abc2'
gmake[3]: Leaving directory `/home/sheena/test_dir/test_dir/abc2'
gmake[3]: Entering directory `/home/sheena/test_dir/test_dir'
/bin/sh ../libtool --silent --mode=link gcc -ansi -W -Wall -pedantic -Wshadow -Wpointer-arith -Wmissing-prototypes -Wwrite-strings -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -O2 -o test_dir ./abc2/a1/liba1.a ./abc2/a2/liba2.a
./abc2/a2/liba2.a(b2.o): In function `main':
/home/sheena/test_dir/test_dir/abc2/a2/b2.cpp:25: undefined reference to `strrev(char*)'
/home/sheena/test_dir/test_dir/abc2/a2/b2.cpp:26: undefined reference to `strlen1(char*)'
/home/sheena/test_dir/test_dir/abc2/a2/b2.cpp:27: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/home/sheena/test_dir/test_dir/abc2/a2/b2.cpp:27: undefined reference to `std::cout'
/home/sheena/test_dir/test_dir/abc2/a2/b2.cpp:27: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/home/sheena/test_dir/test_dir/abc2/a2/b2.cpp:27: undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
/home/sheena/test_dir/test_dir/abc2/a2/b2.cpp:27: undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
./abc2/a2/liba2.a(b2.o): In function `__static_initialization_and_destruction_0':
/usr/include/c++/3.2/iostream:62: undefined reference to `std::ios_base::Init::Init[in-charge]()'
./abc2/a2/liba2.a(b2.o): In function `__tcf_0':
/usr/include/c++/3.2/iostream:62: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
collect2: ld returned 1 exit status
gmake[3]: *** [test_dir] Error 1
gmake[3]: Leaving directory `/home/sheena/test_dir/test_dir'
gmake[2]: Leaving directory `/home/sheena/test_dir/test_dir'
gmake[1]: Leaving directory `/home/sheena/test_dir'
gmake: Leaving directory `/home/sheena/test_dir'
gmake[2]: *** [all-recursive] Error 1
gmake[1]: *** [all-recursive] Error 1
gmake: *** [all] Error 2
*** failed ***

---------------------------------------------------------------------------

if any one know the solution please help me out.

Regards,
Sheena

amit201 06-03-2004 04:18 AM

One solution to this problem is..

keep the file which contain main function in the directory where you have created the project. This is just a workaround. I am working on the root cause of the problem. will let you know as got the final solution.

Regards,
Amit

ashwinipahuja 06-03-2004 07:16 AM

Hi Amit,

Thank you very much.
Its working now.
I just want to know the reason for the same.

Regards,
Sheena


All times are GMT -5. The time now is 10:37 PM.