title: Using Maven to build c++ in eclipse
body: <p>My Project consists of multiple Java-Projects, one Java-JNI-C++ Project as a Bridge and one pure C++ Project keeping an algorithm library. I managed to write Maven build configurations for all 3 project kinds. So when I'm calling them on the commandline (Windows 7, 64bit) everything works great.</p>
  
  <p>I do not use any make files or something like this. I use exec-maven-plugin to call my mingw 64bit installation without cygwin (and I also didn't at least knowingly install msys). So 2 pure commandline g++ commands each for the JNA and Library Project.</p>
  
  <p>What I need now for a smooth development workflow is to be able to build and debug the this projects from within Eclipse but using the maven build scripts, since I don't want to put work into my poms and additionally configure the eclipse builder. This should be consistent! Furthermore should the error parsing in Eclipse be konsistent with the output of the maven build.</p>
  
  <p>For my Java projects this works greatly out of the box. Eclipse picks up the maven config and CLEAN and BUILD produces exactly what it should. (Though I see that the Java Builder is still active in the project's properties. Why??). But I cannot get it to work with the CDT.</p>
  
  <p><strong>When I disable the C++ Builder Eclipse just builds with maven (what I want), but the clean commands do not work correctly. Also I get errors marked which are not errors by the compiler. Of course this should be consistent.</strong></p>
  
  <p>Are there tutorials for this use case?</p>
  
  <p>I did not find information on that subject. I'm not sure if I'm generally going into a wrong direction missing best practices or something?!</p>
  
  <p>Since this is my first s.o. question, please feel free to give me also feedback on my question. What I can provide I will ;-)</p>
  
  <p>Some Information:</p>
  
  <p>System Windows 7, 64bit</p>
  
  <p>Eclipse Juno, m2e</p>
  
  <p>Library POM:</p>
  
  
  
  <pre class="lang-xml prettyprint-override"><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;test&lt;/groupId&gt;
    &lt;artifactId&gt;mylib&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;
    &lt;name&gt;MyLib&lt;/name&gt;
    &lt;build&gt;
      &lt;pluginManagement&gt;
        &lt;plugins&gt;
          &lt;plugin&gt;
            &lt;groupId&gt;org.eclipse.m2e&lt;/groupId&gt;
            &lt;artifactId&gt;lifecycle-mapping&lt;/artifactId&gt;
            &lt;version&gt;1.0.0&lt;/version&gt;
            &lt;configuration&gt;
              &lt;lifecycleMappingMetadata&gt;
                &lt;pluginExecutions&gt;
                  &lt;pluginExecution&gt;
                    &lt;pluginExecutionFilter&gt;
                      &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                      &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
                      &lt;versionRange&gt;[1.1.1,)&lt;/versionRange&gt;
                      &lt;goals&gt;
                        &lt;goal&gt;exec&lt;/goal&gt;
                      &lt;/goals&gt;
                    &lt;/pluginExecutionFilter&gt;
                    &lt;action&gt;
                      &lt;execute&gt;
                        &lt;runOnIncremental&gt;true&lt;/runOnIncremental&gt;
                      &lt;/execute&gt;
                    &lt;/action&gt;
                  &lt;/pluginExecution&gt;
                &lt;/pluginExecutions&gt;
              &lt;/lifecycleMappingMetadata&gt;
            &lt;/configuration&gt;
          &lt;/plugin&gt;
        &lt;/plugins&gt;
      &lt;/pluginManagement&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
          &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
          &lt;version&gt;1.1.1&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;compile-Windows_x64&lt;/id&gt;
              &lt;phase&gt;compile&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;exec&lt;/goal&gt;
              &lt;/goals&gt;
              &lt;configuration&gt;
                &lt;executable&gt;g++&lt;/executable&gt;
                &lt;workingDirectory&gt;target/cpp/Windows_x64&lt;/workingDirectory&gt;
                &lt;arguments&gt;
                  &lt;argument&gt;-Wall&lt;/argument&gt;
                  &lt;argument&gt;-m64&lt;/argument&gt;
                  &lt;argument&gt;-c&lt;/argument&gt;
                  &lt;argument&gt;-DAPI_EXPORT&lt;/argument&gt;
                  &lt;argument&gt;-g3&lt;/argument&gt;
                  &lt;argument&gt;-std=c++0x&lt;/argument&gt;
                  &lt;argument&gt;../../../src/main/cpp/*.cpp&lt;/argument&gt;
                &lt;/arguments&gt;
              &lt;/configuration&gt;
            &lt;/execution&gt;
            &lt;execution&gt;
              &lt;id&gt;link-Windows_x64&lt;/id&gt;
              &lt;phase&gt;compile&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;exec&lt;/goal&gt;
              &lt;/goals&gt;
              &lt;configuration&gt;
                &lt;executable&gt;g++&lt;/executable&gt;
                &lt;workingDirectory&gt;target&lt;/workingDirectory&gt;
                &lt;arguments&gt;
                  &lt;argument&gt;-shared&lt;/argument&gt;
                  &lt;argument&gt;-s&lt;/argument&gt;
                  &lt;argument&gt;-m64&lt;/argument&gt;
                  &lt;argument&gt;-oMyLib_Windows_x64.dll&lt;/argument&gt;
                  &lt;argument&gt;cpp/Windows_x64/*.o&lt;/argument&gt;
                &lt;/arguments&gt;
              &lt;/configuration&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.4&lt;/version&gt;
          &lt;configuration&gt;
            &lt;descriptors&gt;
              &lt;descriptor&gt;src/main/assembly/assembly.xml&lt;/descriptor&gt;
            &lt;/descriptors&gt;
          &lt;/configuration&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;make-assembly&lt;/id&gt;
              &lt;phase&gt;package&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;single&lt;/goal&gt;
              &lt;/goals&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.3.2&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-testCompile&lt;/id&gt;
              &lt;phase&gt;none&lt;/phase&gt;
            &lt;/execution&gt;
            &lt;execution&gt;
              &lt;id&gt;default-compile&lt;/id&gt;
              &lt;phase&gt;none&lt;/phase&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
          &lt;configuration&gt;
            &lt;source&gt;1.7&lt;/source&gt;
            &lt;target&gt;1.7&lt;/target&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.3.2&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-jar&lt;/id&gt;
              &lt;phase&gt;none&lt;/phase&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.10&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-test&lt;/id&gt;
              &lt;phase&gt;none&lt;/phase&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.5&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-resources&lt;/id&gt;
              &lt;phase&gt;none&lt;/phase&gt;
            &lt;/execution&gt;
            &lt;execution&gt;
              &lt;id&gt;default-testResources&lt;/id&gt;
              &lt;phase&gt;none&lt;/phase&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-install-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.3.1&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-install&lt;/id&gt;
              &lt;phase&gt;none&lt;/phase&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-deploy-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.7&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-deploy&lt;/id&gt;
              &lt;phase&gt;none&lt;/phase&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-site-plugin&lt;/artifactId&gt;
          &lt;version&gt;3.0&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-site&lt;/id&gt;
              &lt;phase&gt;none&lt;/phase&gt;
            &lt;/execution&gt;
            &lt;execution&gt;
              &lt;id&gt;default-deploy&lt;/id&gt;
              &lt;phase&gt;none&lt;/phase&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>JNI POM:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;test&lt;/groupId&gt;
    &lt;artifactId&gt;myprog&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;
    &lt;name&gt;MyProg&lt;/name&gt;
    &lt;build&gt;
      &lt;pluginManagement&gt;
        &lt;plugins&gt;
          &lt;plugin&gt;
            &lt;groupId&gt;org.eclipse.m2e&lt;/groupId&gt;
            &lt;artifactId&gt;lifecycle-mapping&lt;/artifactId&gt;
            &lt;version&gt;1.0.0&lt;/version&gt;
            &lt;configuration&gt;
              &lt;lifecycleMappingMetadata&gt;
                &lt;pluginExecutions&gt;
                  &lt;pluginExecution&gt;
                    &lt;pluginExecutionFilter&gt;
                      &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                      &lt;artifactId&gt;truezip-maven-plugin&lt;/artifactId&gt;
                      &lt;versionRange&gt;[1.1,)&lt;/versionRange&gt;
                      &lt;goals&gt;
                        &lt;goal&gt;copy&lt;/goal&gt;
                      &lt;/goals&gt;
                    &lt;/pluginExecutionFilter&gt;
                    &lt;action&gt;
                      &lt;execute&gt;
                        &lt;runOnIncremental&gt;true&lt;/runOnIncremental&gt;
                      &lt;/execute&gt;
                    &lt;/action&gt;
                  &lt;/pluginExecution&gt;
                  &lt;pluginExecution&gt;
                    &lt;pluginExecutionFilter&gt;
                      &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                      &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
                      &lt;versionRange&gt;[1.1.1,)&lt;/versionRange&gt;
                      &lt;goals&gt;
                        &lt;goal&gt;exec&lt;/goal&gt;
                      &lt;/goals&gt;
                    &lt;/pluginExecutionFilter&gt;
                    &lt;action&gt;
                      &lt;execute&gt;
                        &lt;runOnIncremental&gt;true&lt;/runOnIncremental&gt;
                      &lt;/execute&gt;
                    &lt;/action&gt;
                  &lt;/pluginExecution&gt;
                &lt;/pluginExecutions&gt;
              &lt;/lifecycleMappingMetadata&gt;
            &lt;/configuration&gt;
          &lt;/plugin&gt;
        &lt;/plugins&gt;
      &lt;/pluginManagement&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
          &lt;artifactId&gt;truezip-maven-plugin&lt;/artifactId&gt;
          &lt;version&gt;1.1&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;get-library-headers&lt;/id&gt;
              &lt;goals&gt;
                &lt;goal&gt;copy&lt;/goal&gt;
              &lt;/goals&gt;
              &lt;phase&gt;generate-sources&lt;/phase&gt;
              &lt;configuration&gt;
                &lt;fileset&gt;
                  &lt;directory&gt;../MyLib/target/mylib-0.0.1-SNAPSHOT-dll.zip&lt;/directory&gt;
                  &lt;includes&gt;
                    &lt;include&gt;headers/*&lt;/include&gt;
                  &lt;/includes&gt;
                  &lt;outputDirectory&gt;${project.build.directory}/myLib&lt;/outputDirectory&gt;
                &lt;/fileset&gt;
              &lt;/configuration&gt;
            &lt;/execution&gt;
            &lt;execution&gt;
              &lt;id&gt;get-library&lt;/id&gt;
              &lt;goals&gt;
                &lt;goal&gt;copy&lt;/goal&gt;
              &lt;/goals&gt;
              &lt;phase&gt;generate-resources&lt;/phase&gt;
              &lt;configuration&gt;
                &lt;fileset&gt;
                  &lt;directory&gt;../MyLib/target/mylib-0.0.1-SNAPSHOT-dll.zip&lt;/directory&gt;
                  &lt;includes&gt;
                    &lt;include&gt;*.dll&lt;/include&gt;
                  &lt;/includes&gt;
                  &lt;outputDirectory&gt;${project.build.directory}&lt;/outputDirectory&gt;
                &lt;/fileset&gt;
              &lt;/configuration&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
          &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
          &lt;version&gt;1.1.1&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;compile-Windows_x64&lt;/id&gt;
              &lt;phase&gt;compile&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;exec&lt;/goal&gt;
              &lt;/goals&gt;
              &lt;configuration&gt;
                &lt;executable&gt;g++&lt;/executable&gt;
                &lt;workingDirectory&gt;target/cpp/Windows_x64&lt;/workingDirectory&gt;
                &lt;arguments&gt;
                  &lt;argument&gt;-Wall&lt;/argument&gt;
                  &lt;argument&gt;-m64&lt;/argument&gt;
                  &lt;argument&gt;-c&lt;/argument&gt;
                  &lt;argument&gt;-g3&lt;/argument&gt;
                  &lt;argument&gt;-std=c++0x&lt;/argument&gt;
                  &lt;argument&gt;-I../../myLib/headers&lt;/argument&gt;
                  &lt;argument&gt;../../../src/main/cpp/*.cpp&lt;/argument&gt;
                &lt;/arguments&gt;
              &lt;/configuration&gt;
            &lt;/execution&gt;
            &lt;execution&gt;
              &lt;id&gt;link-Windows_x64&lt;/id&gt;
              &lt;phase&gt;compile&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;exec&lt;/goal&gt;
              &lt;/goals&gt;
              &lt;configuration&gt;
                &lt;executable&gt;g++&lt;/executable&gt;
                &lt;workingDirectory&gt;target&lt;/workingDirectory&gt;
                &lt;arguments&gt;
                  &lt;argument&gt;-m64&lt;/argument&gt;
                  &lt;argument&gt;-s&lt;/argument&gt;
                  &lt;argument&gt;-oMyProg_Windows_x64.exe&lt;/argument&gt;
                  &lt;argument&gt;cpp/Windows_x64/*.o&lt;/argument&gt;
                  &lt;argument&gt;MyLib_Windows_x64.dll&lt;/argument&gt;
                &lt;/arguments&gt;
              &lt;/configuration&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.3.2&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-testCompile&lt;/id&gt;
              &lt;phase&gt;none&lt;/phase&gt;
            &lt;/execution&gt;
            &lt;execution&gt;
              &lt;id&gt;default-compile&lt;/id&gt;
              &lt;phase&gt;none&lt;/phase&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
          &lt;configuration&gt;
            &lt;source&gt;1.7&lt;/source&gt;
            &lt;target&gt;1.7&lt;/target&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.3.2&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-jar&lt;/id&gt;
              &lt;phase&gt;none&lt;/phase&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.10&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-test&lt;/id&gt;
              &lt;phase&gt;none&lt;/phase&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.5&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;default-resources&lt;/id&gt;
              &lt;phase&gt;none&lt;/phase&gt;
            &lt;/execution&gt;
            &lt;execution&gt;
              &lt;id&gt;default-testResources&lt;/id&gt;
              &lt;phase&gt;none&lt;/phase&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Thankx</p>