如何在Eclipse中使用nix

时间:2016-04-29 08:14:29

标签: c++ eclipse cmake nix

我正在尝试将包管理器 nix 用于我的C ++项目。

default.nix:

<Style TargetType="Border" x:Key="part_ButtonBorder">
    <Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
    <Setter Property="CornerRadius" Value="30"/>
</Style>  

我构建了项目在其目录中使用 cmake 没有任何问题。然后我将项目导出为Eclipse项目(我在 nix-shell 下完成):

<Style TargetType="Button" x:Key="MainTilesButton">
    <Setter Property="Background" Value="#CCF5F5F5"/>
    <!--This is background colour with opcaity defined-->
    <Setter Property="Margin" Value="20"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Border x:Name="border" Background="{TemplateBinding Background}" Style="{StaticResource part_ButtonBorder}">
                    <Border.RenderTransform>
                        <RotateTransform/>
                    </Border.RenderTransform>
                    <StackPanel>
                        <ContentPresenter VerticalAlignment="Center" 
                            HorizontalAlignment="Center" 
                            TextBlock.FontFamily="Segoe UI Semibold"
                            TextBlock.TextAlignment="Justify" 
                            TextBlock.FontSize="26.667"/>
                        <Path Fill="{TemplateBinding Background}" Stroke="Black" StrokeThickness="1" Data="m 193.2 112.7 -0.3 0.3 -0.6 0 -0.6 -0.3 -2.1 -2.1 -0.3 0 c -1.5 1.5 -3.5 2.6 -7.1 2.6 -4.1 0 -6.8 -2.6 -6.8 -6.2 0 -3.2 2.1 -5 4.4 -5.9 l 0 -0.3 c -0.9 -0.9 -2.1 -2.4 -2.1 -4.4 0 -2.1 1.2 -4.4 4.7 -4.4 3.2 0 4.4 2.4 4.4 4.1 0 3.2 -2.1 4.4 -3.8 5.3 l 0 0.3 5.9 5.9 0.3 0 c 0.6 -1.2 0.9 -2.9 0.9 -5.9 l 0.3 -0.3 1.2 0 0.3 0.3 c 0 3.5 -0.6 5.6 -1.5 7.1 l 0 0.3 2.6 2.6 0 1 z m -5 -3.6 -6.8 -6.8 -0.3 0 c -2.6 0.9 -3.8 2.4 -3.8 4.7 0 2.6 1.8 4.7 5 4.7 2.6 0 4.7 -0.9 5.9 -2.4 l 0 -0.2 z m -5.6 -15.6 c -2.1 0 -2.9 1.2 -2.9 2.9 0 1.5 0.6 2.4 2.1 3.8 l 0.6 0 c 1.8 -0.9 2.9 -1.8 2.9 -3.8 -0.1 -1.4 -0.7 -2.9 -2.7 -2.9 z"/>
                    </StackPanel>
                </Border>
                <ControlTemplate.Triggers>
                    <EventTrigger RoutedEvent="MouseEnter">
                        <BeginStoryboard>
                            <Storyboard>
                                <!--<DoubleAnimation Storyboard.TargetProperty="(Rectangle.RenderTransform).(RotateTransform.Angle)" To="-360" Duration="0:0:1" RepeatBehavior="Forever"/>-->
                                <ThicknessAnimation Storyboard.TargetProperty="Margin" To="10" Duration="0:0:0.2"/>
                                <ColorAnimation 
                                     Storyboard.TargetProperty="(Button.Background).(SolidColorBrush.Color)" 
                                     From="White" To="ForestGreen" Duration="0:00:0.3" />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                    <EventTrigger RoutedEvent="MouseLeave">
                        <BeginStoryboard>
                            <Storyboard>
                                <ThicknessAnimation Storyboard.TargetProperty="Margin" To="20" Duration="0:0:0.2"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter TargetName="border" Property="Background" Value="Red"/>
                    </Trigger>
                    <!--<EventTrigger RoutedEvent="Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <ThicknessAnimation Storyboard.TargetProperty="Margin" To="20" Duration="0:0:0.2"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>-->
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>  

在Eclipse中打开导出的项目后,我发现包含路径很好,并指向/ nix / store / *。但是当我尝试构建项目时,我遇到了一个错误:

  

gtest / gtest.h:没有这样的文件或目录

我看到Eclipse没有向编译器标志添加nix'es路径:

{ pkgs ? import <nixpkgs> {} }:
let
  stdenv = pkgs.stdenv;
in rec {
  myProject = stdenv.mkDerivation {
    name = "lynx";
    version = "dev-0.4.0";
    buildInputs = [
      pkgs.cmake
      pkgs.gtest
    ];
  }; 
}

这可能是问题的原因,但我不知道如何改变Eclipse的行为。

1 个答案:

答案 0 :(得分:1)

根据观点的数量判断问题是非常具体的。但是,我以某种方式找到了解决方案。

导出到Eclipse项目后,我创建了builder.sh文件:

export NIX_PATH=nixpkgs=/home/xxxx/.nix-defexpr/channels/nixpkgs
/home/xxxx/.nix-profile/bin/nix-shell default.nix --run "make $1"

然后我将文件设置为 C \ C ++ General中的构建命令 - &gt; C \ C ++制作项目

bash ${project_loc}/build.sh

就是这样。