Can I compile all .cpp files in src/ to .o’s in obj/, then link to binary in ./?

Makefile part of the question This is pretty easy, unless you don’t need to generalize try something like the code below (but replace space indentation with tabs near g++) SRC_DIR := …/src OBJ_DIR := …/obj SRC_FILES := $(wildcard $(SRC_DIR)/*.cpp) OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRC_FILES)) LDFLAGS := … CPPFLAGS := … CXXFLAGS := … main.exe: $(OBJ_FILES) g++ … Read more

ld linker question: the –whole-archive option

There are legitimate uses of –whole-archive when linking executable with static libraries. One example is building C++ code, where global instances “register” themselves in their constructors (warning: untested code): handlers.h typedef void (*handler)(const char *data); void register_handler(const char *protocol, handler h); handler get_handler(const char *protocol); handlers.cc (part of libhandlers.a) typedef map<const char*, handler> HandlerMap; HandlerMap … Read more

Is it possible to create an “uber” jar containing the project classes and the project dependencies as jars with a custom manifest file?

Actually, I didn’t check what the maven-shade-plugin is doing exactly (or any other plugin) as maven 2 has everything built-in to create a megajar or uberjar. You just have to use the maven-assembly-plugin with the predefined jar-with-dependencies descriptor. Just add this snippet to your pom.xml to customize the manifest: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> … Read more

Building executable jar with maven?

Actually, I think that the answer given in the question you mentioned is just wrong (UPDATE – 20101106: someone fixed it, this answer refers to the version preceding the edit) and this explains, at least partially, why you run into troubles. It generates two jar files in logmanager/target: logmanager-0.1.0.jar, and logmanager-0.1.0-jar-with-dependencies.jar. The first one is … Read more