[Cmake] CMakeLists setup for simple problem

michael_cm at gmx.ch michael_cm at gmx.ch
Wed Jun 2 03:21:07 EDT 2004


Hi,

thanks for the help. The setup you proposed works. However, I had to notice
the following:

In the common directory, I at first had a class Hello which only consisted
of a .h file:

-----
#ifndef __Hello_h
#define __Hello_h

#include <iostream>

class Hello {
public:
	void Print() {
		std::cout << "Hello" << std::endl;
	}
};

#endif
-----

In the CMakeLists.txt file I wrote:

ADD_LIBRARY(mycommon Hello.h)

This setup did not work, I got the error message:

LINK : fatal error LNK1104: cannot open file "mycommon.lib"

Then I split up the Hello class in a .h and a .cxx file and everything
worked fine. Even keeping the implementation in the .h file and adding an
entirely empty .cxx file helped.

Why is this .cxx file necessary?

Thanks,

Michael



> michael_cm at gmx.ch wrote:
> > Hi,
> > 
> > I would like to set up the following directory structure:
> > 
> > src_dir/common
> > src_dir/app1
> > src_dir/app2
> > ...
> > 
> > 
> > In the directory 'common', I'd like to have classes used by application1
> and
> > application2 (and some more applications). The files belonging to these
> > applications (including the file with the main() function) are stored in
> > 'app1', 'app2' and so on.
> > 
> > I'd like to use cmake to create my make files, since I'd like to compile
> the
> > project on different platforms.
> > 
> > Unfortunately I didn't really get it to work and would therefore like to
> > know how to properly set up the CMakeLists.txt files for this (I guess)
> > simple problem.
> 
> # src_dir/CMakeLists.txt
> PROJECT(MYPROJ)
> INCLUDE_DIRECTORIES(${MYPROJ_SOURCE_DIR}/common)
> SUBDIRS(common app1 app2)
> 
> # src_dir/common/CMakeLists.txt
> ADD_LIBRARY(mycommon src1.cxx src2.cxx)
> 
> # src_dir/app1/CMakeLists.txt
> ADD_EXECUTABLE(app1 app1.cxx)
> TARGET_LINK_LIBRARIES(app1 mycommon)
> 
> # src_dir/app2/CMakeLists.txt
> ADD_EXECUTABLE(app2 app2.cxx)
> TARGET_LINK_LIBRARIES(app2 mycommon)
> 
> -Brad
> 

-- 
"Sie haben neue Mails!" - Die GMX Toolbar informiert Sie beim Surfen!
Jetzt aktivieren unter http://www.gmx.net/info



More information about the Cmake mailing list