[CMake] unable to include a source file for all sub directories

ankit jain ankitguddu at gmail.com
Fri May 15 11:05:58 EDT 2009


2009/5/15 <David.Karr at l-3com.com>

> ankit jain <ankitguddu at gmail.com> wrote:
>
> > My source tree structure is:
> > Main_folder
> >.. Ident.c
> >..folder1
> >........f11.c
> >........f12.c
> > [...]
> >
> > Now I am able to get all the source files from all the folders. but
> the
> > problem is that all folder source files uses one variable v1 of this
> Ident.c
> > file..
> >
> > So the error iam getting while building the library is :
> > unresolved external symbol: v1  (iam working on windows VC++)
>
> I suggest the following exercise: use VC++ to create a very simple
> workspace/"solution" with just one VC++ "project" in it that builds a
> library.  Add Ident.c and just a few of your other files (maybe just
> f11.c) to this project.  Then try to build this project.
>
> Now either one of two things will happen:
>
> 1. You will get the same link errors as before.  Then you know your
> problem is that you have incorrect C++ code; CMake did not cause the
> problem and cannot solve it.  You might then try asking a C/C++ forum
> what is wrong, but before you do that you should delete as much code
> from Ident.c and f11.c as possible while making sure you still get the
> same error when you try to build the code.  Then you can post the
> complete contents of these files when asking your question.  (You will
> probably not get an answer if you don't post code, or if you post more
> than a couple of pages of code.  Many people are willing to help, but
> not if they have to do a lot of work that you could have done yourself.)
>
> 2. You will not get the same link errors.  Then you may be able to find
> some difference in the settings of the projects (between the project
> created by CMake and the one you created directly in VC++) that explains
> why there is an error only in the CMake project.
>
> I have a very strong hunch you will get the first result.
>
> David A. Karr
>

Thanks for the suggestion David but ht eproblem is still there. i will give
you the content of two files with the tree structure. i request you to do
the same for me on your machine and see whether it gives error or not..

mainfolder
...Ident.c
...subfolder
.........file.c

Ident.c contain:

int number=10;
char array[]="hello";

subfolder/file.c contains:

#some header files
extern int number;
print("iam in sub folder");

Now cmakelists of mainfolder is:

Project (mainfolder)

foreach(fname ${subfolder_srcs})
list(APPEND mainfolder_srcs subfodler/${fname})
endforeach(fname)

list(APPEND mainfolder_srcs Ident.c)
add_library(mylib SHARED ${mainfolder_srcs})


CMakelist of subfolder..

set(subfolder _srcs file.c)
set(subfodler_srcs ${subfolder_srcs} PARENT_SCOPE)

Thats it..

Compiling is ok .. Ident.obj and file.obj created..
But when it creating mylib library in linking it says:
file.obj : unresolved external symbol: int number

if the tree structure is like this:
mainfolder
....Ident.c
....file.c

Means no subfolder direct file in mainfolder. then there is no problem in
creating the library.
Because of accessing file from subfolder it creates problem..

Also if in VC++ if i give addtional option in compilation as /FI"filepath to
Ident.c"
Then it works..
because file.c is compiled with Ident.c
so it works but i dont want to give this flag in compiler option...

Why it is not taking directly...

I hope i make my question very clear...

Regards-
Ankit Jain..




> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090515/0d09941f/attachment.htm>


More information about the CMake mailing list