this post was submitted on 16 Aug 2023
6 points (100.0% liked)

nixos

1262 readers
8 users here now

All about NixOS - https://nixos.org/

founded 4 years ago
 

I couldn't find a nix community, so I'm hoping it is ok that I'm posting on the nixos one instead. I'll switch to mailing list/discord if necessary, but I have a lemmy app on my phone, and it is much easier to have an ongoing conversation from here, so I decided to give it a shot. Here goes!

While I have a NixOS laptop, I primarily use other systems (e.g. OpenSuse Tumbleweed) as of now.

I love the ability to define the packages I want installed, with home-manager managing my command line utilities (e.g mtr, dig, protobuf etc).

I've been playing around a bit with protobuf recently, and after generating some c++ code using protoc, I loaded up the generated code in vscode, which understandably wasn't able to find the development headers for protobuf (since they are in the nix store - /nix/store/h2h5fs8iv2a8rmlkfhr6id6y4jxwd5i1-protobuf-3.21.12/include/google/protobuf/io)

I tried to compile the code anyways on the command line, and got some errors.

I might need an OS specific protobuf install just for the development headers, but I'm pretty sure I should be able to, and just don't know how. Here's what I get when I try to compile:

$ g++ searchReq.pb.cc
In file included from searchReq.pb.cc:4:
searchReq.pb.h:10:10: fatal error: google/protobuf/port_def.inc: No such file or directory
   10 | #include 
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

Any tips/pointers would be appreciated. Thanks in advance!

===========================================

Edit: Thank you all, particularly @[email protected] and @[email protected] for the help. After setting the include path (compile) and LD_LIBRARY_PATH (link), things work great.

I ended up writing a small Makefile for convenience in the short run:

INC_FLAGS:=-I$(HOME)/.nix-profile/include -Icpp
LD_FLAGS:=-L$(HOME)/.nix-profile/lib -l protobuf

run: task
	LD_LIBRARY_PATH=$(HOME)/.nix-profile/lib ./task

task:
	g++ $(LD_FLAGS) $(INC_FLAGS) main.cpp cpp/searchReq.pb.cc -o task

regen:
	protoc --python_out=python --cpp_out=cpp searchReq.proto

That's enough to get me going for now.

TODO - read up the NIXOs Wiki C page in more detail

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 1 year ago

- works now, thank you!