Skip to content

Instantly share code, notes, and snippets.

@likev
likev / Building and Linking Libraries in C on Linux.md
Created December 23, 2016 11:52
Building and Linking Libraries in C on Linux

C Libraries

In general, libraries are created from many library source files, and are either built as archive files (libmine.a) that are statically linked into executables that use them, or as shared object files (libmine.so) that are dynamically linked into executables that use them. To link in libraries of these types, use the gcc command line options -L for the path to the library files and -l to link in a library (a .so or a .a):

-L{path to file containing library} -l${library name}

For example, if I have a library named libmine.so in /home/newhall/lib/ then I'd do the following to link it into my program:

$ gcc -o myprog myprog.c  -L/home/newhall/lib -lmine

You may also need to specify and include path so the compiler can find the library header file: -I /home/newhall/include

@likev
likev / Building and Linking Libraries in C on Linux.html
Created December 23, 2016 12:14
Building and Linking Libraries in C on Linux
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Building and Linking Libraries in C on Linux</title>
<link rel="stylesheet" href="https://stackedit.io/res-min/themes/base.css" />
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
</head>
<body><div class="container"><h2 id="c-libraries">C Libraries</h2>
@likev
likev / tuple_each.cpp
Last active December 20, 2018 05:38
function like std::for_each with tuple
/*
test with vs2017
*/
#include<tuple>
#include<iostream>
// helper function to tuple_each a tuple of any size
template<class Tuple, typename Func, std::size_t N>
struct TupleEach {
@likev
likev / htons-htonl-ntohs-ntohl.cpp
Created August 6, 2017 08:17
convert between Big-endian(TCP/IP network) byte order and Little-endian(host) byte order
namespace nh {
auto htons = [](unsigned short h)
{
return (unsigned short)
( h << 8 & 0xFF00U |
h >> 8 & 0x00FFU );
};
auto htonl = [](unsigned int h)
//POST http://zjxy.ghlearning.com/Study/Learning/Question?medId=6cbb298a4b66420db03ab87968c05e98&sscId=d2eb90a25495499f90895893fd7af434
//timespan=-3600
<script type="text/javascript">
function CloseAlertDialog(btn)
{
var length = 0;
var isCorrect = true;
//茅陋艗猫炉聛忙藴炉氓聬娄莽颅鈥澝┞⑺?
@likev
likev / max_sum_submatrix.cpp
Last active June 2, 2022 12:46
Given an n by m matrix of integers, find the submatrix with the maximum sum. Return the sum, left, right, top, bottom.
#include "max_sum_submatrix.h"
#include <iostream>
#include <vector>
int main()
{
std::vector<int> v = { 4,6,8,3,-233,6,5,-2,83,2,3,6,4 };
std::vector< std::vector<int> > matirx = {
@likev
likev / extract.js
Created September 12, 2017 06:15
extract info line by line with Node.js (usage: node extract.js <ln.txt > result-ln.txt)
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const processLine = (line)=>{
var is_wu = false, is_mai=false;
if(line.search(/[^轻]雾/) !== -1){
@likev
likev / --parent.js
Last active August 30, 2022 18:48
Node.js IO pipes with c++ child_process
const { execFile } = require('child_process');
const child = execFile('child-cpp');
process.stdin.setEncoding('utf8');
process.stdin.on('readable', () => {
const chunk = process.stdin.read();
if (chunk !== null) {
//parent.stdin as child.stdin;
child.stdin.write(chunk);
@likev
likev / -connect-and-query.js
Last active May 18, 2018 10:36
Apache Cassandra access with cassandra-driver
const cassandra = require('cassandra-driver');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const client = new cassandra.Client({ contactPoints: ['10.69.72.113'] });
@likev
likev / micaps4-station-read.js
Created May 17, 2018 10:06
read micaps4 station binary data
const fs = require('fs');
const jBinary = require('jbinary');
const iconv = require('iconv-lite');
var typeSet = {
'jBinary.littleEndian': true,
header: {
discriminator: ['string', 4],
type: 'uint16',
description: ['string', 100],