Scooter
Scooter

Reputation: 7059

Why is SCons saying that my hpp file is static and cannot be used to make a shared library?

I have a set of C++ files that I can compile as static, but when I try and build it as dynamic

env.SharedLibrary("mylib",["Object.hpp", "Object.cpp"]

SCons gives me this error:

scons: done reading SConscript files.
scons: Building targets ...
scons: *** [libjava.so] Source file: Object.hpp is static and is not compatible with shared target: libmylib.so
scons: building terminated because of errors.

This is Object.hpp that is is rejecting:

#ifndef _OBJECT__HPP
#define _OBJECT__HPP


namespace java {

typedef bool boolean;
typedef char byte;


class String;

class Object {
  public:
    virtual String toString(void) const;
};


}

#endif

Upvotes: 1

Views: 654

Answers (1)

dirkbaechle
dirkbaechle

Reputation: 4052

Just don't add the header to the list of direct sources for the lib. Set the CPPPATH variable correctly and let SCons find the header itself, which will add it as implicit dependency. For more infos on this, check out the SCons UserGuide at http://www.scons.org/doc/production/HTML/scons-user.html , "6.3 Implicit dependencies".

(Remark: You don't seem to have a problem with your object files, yet, but if you should ever want to use the same source/object file for creating a shared and a static lib, you'll have to give them different names. The created object files get internally tagged whether they go into a shared or static lib later, so you have to avoid name clashing here...just sayin'.)

Upvotes: 4

Related Questions