Skip to content

Xcode not working with tidylib #751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
eduhh94 opened this issue Aug 28, 2018 · 4 comments
Closed

Xcode not working with tidylib #751

eduhh94 opened this issue Aug 28, 2018 · 4 comments

Comments

@eduhh94
Copy link

eduhh94 commented Aug 28, 2018

Dear Devolper Team,

I tried to get this example working:

#include <tidy.h>
#include <tidybuffio.h>
#include <stdio.h>
#include <errno.h>


int main(int argc, char **argv )
{
    const char* input = "<title>Foo</title><p>Foo!";
    TidyBuffer output = {0};
    TidyBuffer errbuf = {0};
    int rc = -1;
    Bool ok;
    
    TidyDoc tdoc = tidyCreate();                     // Initialize "document"
    printf( "Tidying:\t%s\n", input );
    
    ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes );  // Convert to XHTML
    if ( ok )
        rc = tidySetErrorBuffer( tdoc, &errbuf );      // Capture diagnostics
    if ( rc >= 0 )
        rc = tidyParseString( tdoc, input );           // Parse the input
    if ( rc >= 0 )
        rc = tidyCleanAndRepair( tdoc );               // Tidy it up!
    if ( rc >= 0 )
        rc = tidyRunDiagnostics( tdoc );               // Kvetch
    if ( rc > 1 )                                    // If error, force output.
        rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 );
    if ( rc >= 0 )
        rc = tidySaveBuffer( tdoc, &output );          // Pretty Print
    
    if ( rc >= 0 )
    {
        if ( rc > 0 )
            printf( "\nDiagnostics:\n\n%s", errbuf.bp );
        printf( "\nAnd here is the result:\n\n%s", output.bp );
    }
    else
        printf( "A severe error (%d) occurred.\n", rc );
    
    tidyBufFree( &output );
    tidyBufFree( &errbuf );
    tidyRelease( tdoc );
    return rc;
}

My problem is that I get the following error all the time and I just can't fix it:

Undefined symbols for architecture x86_64:
"_tidyBufFree", referenced from:
_main in main.o
"_tidyCleanAndRepair", referenced from:
_main in main.o
"_tidyCreate", referenced from:
_main in main.o
"_tidyOptSetBool", referenced from:
_main in main.o
"_tidyParseString", referenced from:
_main in main.o
"_tidyRelease", referenced from:
_main in main.o
"_tidyRunDiagnostics", referenced from:
_main in main.o
"_tidySaveBuffer", referenced from:
_main in main.o
"_tidySetErrorBuffer", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What I did?

  • I set up the header search path to "/usr/local/Cellar/tidy-html5/5.6.0/include/"
  • I set up the library search path to "/usr/local/Cellar/tidy-html5/5.6.0/lib/"
  • I also tried to set other link flags to "-ltidylib"

System?

  • MacOS High Sierra 10.13.4
  • XCode 9.4.1

Solution
Instead of using "-ltidylib" you have to use "-ltidy"

@balthisar
Copy link
Member

I use this template for working with Tidy. I see that you're trying to link to a homebrew installed Tidy, but the linked Xcode project will statically link. Given Tidy's small size, I think it's worth it to keep up with the latest source.

In any case, is there a request to the devs here?

@eduhh94
Copy link
Author

eduhh94 commented Aug 29, 2018

Hi balthisar,

like I already mentioned the problem was a wrong linker flag.
If you install tidy over homebrew you have to do the following to be able to use tidy-html:

First you go to your xcode project and go to "Build Settings" there you add following settings:

  • Header Search Paths: "/usr/local/Cellar/tidy-html5/5.6.0/include"
  • Library Search Paths: "/usr/local/Cellar/tidy-html5/5.6.0/lib"
  • Other Linker Flags: "-ltidy"

The request would be to add this instruction to the set up section for mac installation.

@balthisar
Copy link
Member

The wrong linker flag is where, though? Tidy builds using CMake, and it builds just fine on macOS, using the standard install locations. The Xcode project I provided builds just fine, too. Homebrew seems to be the outlier here.

I'm happy to help, but where, specifically in the setup section would you want this? Since it seems like you're only talking about documentation, a PR would be welcome, so that I understand you completely.

@traviskirton
Copy link

traviskirton commented Feb 14, 2023

I'm running into the same issue, and @balthisar's question from Aug 29, 2018 is still valid.
I have a version of tidy installed via cmake (v 5.9.20) and when I run tidy -v from a script being run from Xcode, the version returned is:
HTML Tidy for Mac OS X released on 31 October 2006 - Apple Inc. build 8765

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants