Editing Example libbu

From BRL-CAD

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 15: Line 15:
 
</code>
 
</code>
  
Building software involves compiling source code, linking objects, and running our application. No matter what compiler or operating system you use, there are options for all three of those:
+
To compile, you need to specify paths to headers (so the #include lines work).
 +
* For gcc/clang, this is usually -I options.
 +
To link, you need to specify paths and libraries to link (so it can find functions).
 +
* For gcc/clang, this is usually -L options and -l options.
 +
To run, you need to specify run paths to libraries (so it can use functions).
 +
* For gcc/clang, this is usually an -rpath linker option.
  
* To ''compile'', you need to specify paths to headers (so the #include lines work).
+
So say we put that <code>test.cpp</code> file in ~/brlcad and have BRL-CAD compiled at ~/brlcad/.build but not installed.  (You don't need to install to use any library -- you just need to know where to find its headers and libraries!)  After changing directory to ~/brlcad, we can compile and link our little test program:
** For gcc/clang, this is usually -I options.
 
* To ''link'', you need to specify paths and libraries to link (so it can find functions).
 
** For gcc/clang, this is usually -L options and -l options.
 
* To ''run'', you need to specify run paths to libraries (so it can use functions).
 
** For gcc/clang, this is usually an -rpath linker option.
 
 
 
So say we put that <code>test.cpp</code> file in ~/brlcad and have BRL-CAD compiled at ~/brlcad/.build but not installed.  (You don't need to install to use any library -- you just need to know where to find headers and libs!)  After changing directory to ~/brlcad, we can compile, link, and run our little test program:
 
  
 
<code><pre>
 
<code><pre>
 
c++ -c -Iinclude -I.build/include test.cpp
 
c++ -c -Iinclude -I.build/include test.cpp
 
c++ test.o -L.build/lib -Wl,-rpath -Wl,.build/lib -lbu
 
c++ test.o -L.build/lib -Wl,-rpath -Wl,.build/lib -lbu
./a.out
 
 
</pre></code>
 
</pre></code>
  
Woot!  If you didn't confuse l with 1, put the wrong path, or mix something else up, you should see:
+
Woot!  Let's run to see it in action:
  
<code>
+
<code><pre>
Program name is a.out
+
./a.out
</code>
+
Program name is a.out
 +
</pre></code>
  
And that's essentially all there is to it!  We can even simplify the entire process into one compile+link command if we are careful enough to make sure include flags come ''before'' source files and linker flags come ''after'' the source files in the right order:
+
So that's all there is to it!  We can even simplify the entire process into one compile+link command if we are careful enough to make sure include flags come ''before'' source files and linker flags come ''after'' the source files, like this:
  
 
<code>
 
<code>
Line 44: Line 42:
 
</code>
 
</code>
  
From there, we set up to use any function in LIBBU.  If we want to link against another library like LIBRT or LIBGED, we already have the right paths so we'd simply add -lrt or -lged respectively to the link line.  To find functions, we can browse around the headers and subdirs in the include directory as nearly every public function is documented in detail there with comments, often with code snippet examples too.
+
From there, we can use any function in LIBBU.  If we want to link against another library like LIBRT or LIBGED, we already have the right paths specified so we'd simply add -lrt or -lged respectively to the link line.  To find functions, we can browse around the include/ headers and subdirectories as nearly every public function is documented in detail there, often with code snippet examples.
  
If we already installed BRL-CAD into /opt/brlcad and want to use all headers and all the core libraries, the process remains the same.  Specify paths to headers, source file(s), paths to libs, and then the libs need:
+
Even if we installed BRL-CAD into /opt/brlcad and want to use all headers and all the core libraries, the process remains the same.  Specify paths to headers, source file(s), paths to libs, and then libs:
  
 
<code>
 
<code>

Please note that all contributions to BRL-CAD may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see BRL-CAD:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)